⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 record.java

📁 八皇后游戏
💻 JAVA
字号:
/*
 * Record.java
 *
 * Created on 2008年4月13日, 下午9:48
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package javaapplication15;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.*;
import java.util.LinkedList;
import javax.swing.*;

/**
 *
 * @author vivi
 */
public class Record extends JFrame implements ActionListener{
    public int time=0;
    public JTextField yourname,label;
    public JButton sure,cancel;
    File gradeFile=null;
    
    /** Creates a new instance of Record */
    public Record(File f) {
        super("记录你的成绩到:"+f.toString());
        gradeFile=f;
        setBounds(100,100,330,160);
        setResizable(false);
        setVisible(false);
        sure=new JButton("确定");
        cancel=new JButton("取消");
        yourname=new JTextField(8);
        yourname.setText("匿名");
        sure.addActionListener(this);
        cancel.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(sure);
        p.add(cancel);
        con.add(p);
         addWindowListener(new WindowAdapter()
    {
        public void windowClosing(WindowEvent e)
        {
            setVisible(false);
            dispose();
        }
         }
         );
              
    }
  
   
    
    public void setTime(int time)
    {
        this.time=time;
    }
    
    public void actionPerformed(ActionEvent e) {
       if(e.getSource()==sure) 
       {
        try{                                                                //将成绩等信息写入文件
            FileInputStream in=new FileInputStream(gradeFile);
            ObjectInputStream object_in=new ObjectInputStream(in);
            LinkedList list=(LinkedList)object_in.readObject();
            object_in.close();
            Player pl=new Player(yourname.getText(),time);
            list.add(pl);
            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()==cancel)                            //取消录入排行榜
       {
           setVisible(false);
           dispose();
       }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -