?? showrecord.java
字號:
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ShowRecord extends JDialog implements ActionListener
{
File gradeFile=null;
JButton 確定,清除;
JTextArea show=null;
public ShowRecord(JFrame frame,File f)
{
super(frame,"記憶測試排行榜:"+f.toString());
gradeFile=f;
show=new JTextArea(6,4);
確定=new JButton("顯示排行榜");
確定.addActionListener(this);
清除=new JButton("清空排行榜");
清除.addActionListener(this);
Container con=getContentPane();
con.add(new JScrollPane(show),BorderLayout.CENTER);
JPanel p=new JPanel();
p.add(確定);
p.add(清除);
con.add(p,BorderLayout.SOUTH);
setBounds(100,100,320,185);
setVisible(false);
setModal(true);
addWindowListener(new WindowAdapter()
{
public void windwoClosing(WindowEvent e)
{
setVisible(false);
dispose();
}
}
);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==確定)
{
try
{
show.setText(null);
FileInputStream in=new FileInputStream(gradeFile);
ObjectInputStream object_in=new ObjectInputStream(in);
LinkedList 成績=(LinkedList)object_in.readObject();
object_in.close();
sort(成績);
for(int i=0;i<成績.size();i++)
{
People people=(People)成績.get(i);
show.append("\n"+people.getName()+"成績:"+people.getTime());
}
}
catch(Exception ee)
{
}
}
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)
{
}
}
}
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);
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -