📄 record.java
字号:
package PetsFinder;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
public class Record extends JFrame implements ActionListener{
private int time=0;
JTextField name,lable;
JButton 确定,取消;
File gradefile=null;
JLabel 时间=null;
public Record(File gradefile,JLabel 显示时间) {
super("排行榜");
this.gradefile=gradefile;
this.时间=显示时间;
setBounds(100,100,330,160);
setResizable(false);
setVisible(false);
确定=new JButton("确定");
取消=new JButton("取消");
确定.setBackground(Color.white);
取消.setBackground(Color.white);
确定.setFont(new java.awt.Font("华文新魏", 1, 20));
取消.setFont(new java.awt.Font("华文新魏", 1, 20));
确定.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
取消.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
确定.addActionListener(this);
取消.addActionListener(this);
name=new JTextField(8);
name.setText("匿名");
lable=new JTextField("输入姓名");
lable.setEditable(false);
lable.setFont(new java.awt.Font("华文新魏", 1, 20));
Container con=getContentPane();
con.setLayout(new GridLayout(2,1));
JPanel p=new JPanel();
con.add(lable);
p.add(name);
p.add(确定);
p.add(取消);
con.add(p);
}
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();
Hero people=new Hero(name.getText(),time);
list.add(people);
FileOutputStream out=new FileOutputStream(gradefile);
ObjectOutputStream object_out=new ObjectOutputStream(out);
object_out.writeObject(list);
object_out.close();
out.close();
}catch(Exception event){
System.out.print(event);
}
this.setVisible(false);
this.dispose();
// URL musicUrl = getClass().getResource("gamewin.wav");
// AudioClip backGroundMusic = java.applet.Applet.newAudioClip(musicUrl);
// backGroundMusic.play();
时间.setText("所用时间:0秒");
}
if(e.getSource()==取消){
this.setVisible(false);
this.dispose();
时间.setText("所用时间:0秒");
}
}
public void setTime(int t){
this.time=t;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -