⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.java

📁 八皇后源代码 JAVA课设 应该满足您的要求
💻 JAVA
字号:
/*
 * f4.java
 *
 * Created on 2008年3月16日, 下午11:03
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package eight;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

/**
 *
 * @author 刘杨
 */
public class file extends JPanel implements ActionListener{
    File gradefile=null;
    JButton 确定,重新记录;
    JTextArea show=null;
    ShowRecord showrecord;
    /** Creates a new instance of f4 */
    public file(File file,ShowRecord showrecord) {
        /** Creates a new instance of ShowRecord */
        this.showrecord=showrecord;
        this.gradefile=file;
        show=new JTextArea(6,4);
        确定=new JButton("确定");
        重新记录=new JButton("重新记录");
        确定.addActionListener(this);
        重新记录.addActionListener(this);
        this.setLayout(new BorderLayout());
        this.add(new JScrollPane(show),BorderLayout.CENTER);
        JPanel p=new JPanel();
        p.add(确定);
        p.add(重新记录);
        this.add(p,BorderLayout.SOUTH);
        show.setEditable(false);
        try{
            show.setText(null);
            FileInputStream in=new FileInputStream(file);
            ObjectInputStream object_in=new ObjectInputStream(in);
            LinkedList list =(LinkedList)object_in.readObject();
            object_in.close();
            this.sort(list);
            for(int i=0;i<list.size();i++) {
                People people=(People)list.get(i);
                show.append(people.getName()+"      成绩:"+people.getTime()+"秒\n");
            }
        }catch(Exception ee){}
        
    }
    
    public void sort(LinkedList list) {
        for(int i=0;i<list.size()-1;i++) {
            for(int j=i+1;j<list.size();j++) {
                if(((People)list.get(i)).getTime()>((People)list.get(j)).getTime()) {
                    People temp=(People)list.get(j);
                    list.set(j,(People)list.get(i));
                    list.set(i,temp);
                }
            }
        }
    }
    
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==确定){
        showrecord.setVisible(false);
        showrecord.dispose();
        }
        
        if(e.getSource()==重新记录){
        try
         {
           FileInputStream in=new FileInputStream(gradefile);
           ObjectInputStream object_in=new ObjectInputStream(in);
           LinkedList 成绩=(LinkedList) object_in.readObject();
           object_in.close();
           成绩.clear();
           FileOutputStream out=new FileOutputStream(gradefile);
           ObjectOutputStream object_out=new ObjectOutputStream(out);
           object_out.writeObject(成绩);
           out.close();
           object_out.close(); 
           show.setText("排行榜被清空");
         }
        catch(Exception ee)
         {
         }
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -