📄 record.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.LinkedList;
public class Record extends JDialog implements ActionListener
{
JButton yes,no;
JTextField yourName,message;
JPanel panel1,panel2,panel3;
JLabel label1,label2;
int score=0;
File gradeFile=null;
public Record(JFrame f,String s,boolean b,File l)
{
super(f,s,b);
gradeFile=l;
setBounds(180,200,300,120);
panel1=new JPanel();
panel2=new JPanel();
panel3=new JPanel();
this.getContentPane().setLayout(new GridLayout(3,1));
this.getContentPane().add(panel1);
this.getContentPane().add(panel2);
this.getContentPane().add(panel3);
yes=new JButton("确定");
no=new JButton("取消");
label1=new JLabel();
label2=new JLabel();
yes.addActionListener(this);
no.addActionListener(this);
panel3.add(label1);
panel3.add(label2);
panel3.add(yes);
panel3.add(no);
message=new JTextField("请输入的您的姓名:");
message.setEditable(false);
panel1.add(message);
yourName=new JTextField(8);
yourName.setText("匿名");
panel2.add(yourName);
this.validate();
}
public void setFile(File f)
{
this.gradeFile=f;
}
public void setScore(int c)
{
this.score=c;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==yes)
{
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(),score);
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()==no)
{
setVisible(false);
dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -