?? record.java
字號:
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Record extends JFrame implements ActionListener
{
int time=0;
JTextField yourName,label;
JButton 確定,取消;
File gradeFile=null;
public Record(File f)
{
super("記錄你的成績到:"+f.toString());
gradeFile=f;
setBounds(100,100,330,160);
setResizable(false);
setVisible(false);
確定=new JButton("確定");
取消=new JButton("取消");
yourName=new JTextField(8);
yourName.setText("匿名");
確定.addActionListener(this);
取消.addActionListener(this);
Container con=getContentPane();
con.setLayout(new GridLayout(2,1));
label=new JTextField("輸入你的姓名,將成績存放到排行榜:"+f.toString());
label.setEditable(false);
con.add(label);
JPanel p=new JPanel();
p.add(yourName);
p.add(確定);
p.add(取消);
con.add(p);
addWindowListener(new WindowAdapter()
{
public void windwoClosing(WindowEvent e)
{
setVisible(false);
dispose();
}
}
);
}
public void setFile(File f)
{
gradeFile=f;
}
public void setTime(int time)
{
this.time=time;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==確定)
{
try{
FileInputStream in=new FileInputStream(gradeFile);
ObjectInputStream object_in=new ObjectInputStream(in);
LinkedList list=(LinkedList)object_in.readObject();
object_in.close();
in.close();
People people=new People(yourName.getText(),time);
list.add(people);
FileOutputStream out=new FileOutputStream(gradeFile);
ObjectOutputStream object_out=new ObjectOutputStream(out);
object_out.writeObject(list);
out.close();
object_out.close();
}
catch(Exception event)
{
System.out.println(event);
}
setVisible(false);
dispose();
}
if(e.getSource()==取消)
{
setVisible(false);
dispose();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -