📄 file.java
字号:
package PetsFinder;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class file extends JPanel implements ActionListener{
File gradefile=null;
JButton 确定,重新记录;
JTextArea show=null;
ShowRecord showrecord;
public file(File file,ShowRecord 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(gradefile);
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++) {
Hero hero=(Hero)list.get(i);
show.append(hero.getName()+" 成绩:"+hero.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(((Hero)list.get(i)).getTime()>((Hero)list.get(j)).getTime()) {
Hero temp=(Hero)list.get(j);
list.set(j,(Hero)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 + -