ShowRecord.java
上传用户:penghbff
上传日期:2007-04-16
资源大小:32k
文件大小:4k
源码类别:

射击游戏

开发平台:

Java

  1. import java.io.*;
  2. import java.util.*;
  3. import javax.swing.*;
  4. import java.awt.event.*;
  5. import java.awt.*;
  6. public class ShowRecord extends JDialog implements ActionListener
  7.   File f=new File("英雄榜.txt");
  8.   String name=null;
  9.   Hashtable hashtable=null;
  10.   JButton 确定,重新记分;
  11.   JLabel label初级[],label中级[],label高级[];
  12.   public ShowRecord(JFrame frame,Hashtable h)
  13.   {
  14.     super(frame,"扫雷英雄榜");
  15.     hashtable=h;
  16.     setBounds(100,100,320,185);
  17.     setResizable(false);
  18.     setVisible(false);
  19.     setModal(true); 
  20.     label初级=new JLabel[3];
  21.     label中级=new JLabel[3];
  22.     label高级=new JLabel[3];
  23.     for(int i=0;i<3;i++)
  24.      {
  25.       label初级[i]=new JLabel();
  26.       label初级[i].setBorder(null);
  27.       label中级[i]=new JLabel();
  28.       label中级[i].setBorder(null);
  29.       label高级[i]=new JLabel();
  30.       label高级[i].setBorder(null);
  31.      } 
  32.     label初级[0].setText("初级");
  33.     label初级[1].setText(""+999); 
  34.     label初级[1].setText("匿名");  
  35.     label中级[0].setText("中级");
  36.     label中级[1].setText(""+999); 
  37.     label中级[1].setText("匿名");
  38.     label高级[0].setText("高级");
  39.     label高级[1].setText(""+999); 
  40.     label高级[1].setText("匿名"); 
  41.     JPanel pCenter=new JPanel();
  42.     pCenter.setLayout(new GridLayout(3,3)); 
  43.     for(int i=0;i<3;i++)
  44.      {
  45.       pCenter.add(label初级[i]);
  46.      } 
  47.     for(int i=0;i<3;i++)
  48.      {
  49.       pCenter.add(label中级[i]);
  50.      }
  51.     for(int i=0;i<3;i++)
  52.      {
  53.       pCenter.add(label高级[i]);
  54.      }
  55.     pCenter.setBorder(BorderFactory.createTitledBorder("扫雷英雄榜"));           
  56.     确定=new JButton("确定");
  57.     重新记分=new JButton("重新记分");
  58.     确定.addActionListener(this);
  59.     重新记分.addActionListener(this);
  60.     JPanel pSouth=new JPanel();
  61.     pSouth.setLayout(new FlowLayout(FlowLayout.RIGHT));
  62.     pSouth.add(重新记分);
  63.     pSouth.add(确定);
  64.     Container con=getContentPane();
  65.     con.add(pCenter,BorderLayout.CENTER);
  66.     con.add(pSouth,BorderLayout.SOUTH) ;
  67.     addWindowListener(new WindowAdapter()
  68.                         {
  69.                           public void windwoClosing(WindowEvent e)
  70.                             {
  71.                               setVisible(false);
  72.                               dispose();
  73.                             }
  74.                         }
  75.                      ); 
  76.    }
  77.  public void 显示记录()
  78.    {
  79.       try{
  80.           FileInputStream in=new FileInputStream(f);
  81.           ObjectInputStream object_in=new ObjectInputStream(in);
  82.           hashtable=(Hashtable)object_in.readObject();
  83.           object_in.close();
  84.           in.close(); 
  85.           String temp=(String)hashtable.get("初级");
  86.           StringTokenizer fenxi=new StringTokenizer(temp,"#");
  87.           label初级[0].setText(fenxi.nextToken());
  88.           label初级[1].setText(fenxi.nextToken());
  89.           label初级[2].setText(fenxi.nextToken());  
  90.           temp=(String)hashtable.get("中级");
  91.           fenxi=new StringTokenizer(temp,"#");
  92.           label中级[0].setText(fenxi.nextToken());
  93.           label中级[1].setText(fenxi.nextToken());
  94.           label中级[2].setText(fenxi.nextToken());  
  95.           temp=(String)hashtable.get("高级");
  96.           fenxi=new StringTokenizer(temp,"#");
  97.           label高级[0].setText(fenxi.nextToken());
  98.           label高级[1].setText(fenxi.nextToken());
  99.           label高级[2].setText(fenxi.nextToken()); 
  100.         }
  101.      catch(Exception e)
  102.         {
  103.            System.out.println(e);
  104.         }
  105.   }
  106.   public void actionPerformed(ActionEvent e)
  107.   { 
  108.     if(e.getSource()==重新记分)
  109.      {
  110.        hashtable.put("初级","初级#"+999+"#匿名"); 
  111.        hashtable.put("中级","中级#"+999+"#匿名");
  112.        hashtable.put("高级","高级#"+999+"#匿名");
  113.        try{
  114.            FileOutputStream out=new FileOutputStream(f);
  115.            ObjectOutputStream object_out=new ObjectOutputStream(out);
  116.            object_out.writeObject(hashtable);
  117.            object_out.close();
  118.            out.close();
  119.          }
  120.        catch(IOException event)
  121.          {
  122.          }
  123.        setVisible(false);
  124.        dispose();
  125.      }
  126.     if(e.getSource()==确定)
  127.      {
  128.        setVisible(false);
  129.        dispose();
  130.      }  
  131.   }
  132. }