?? game.java
字號:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.io.*;
public class Game extends JFrame implements ActionListener
{
JMenuBar bar;
JMenu fileMenu;
JMenuItem 初級,中級,高級,掃雷英雄榜;
int grade=2;
MineSquare 雷陣;
JButton buttonPerson;
Container con;
JPanel box;
File 英雄榜=new File("英雄榜.txt");
Hashtable hashtable=null;
Record 記錄對話框=null;
ShowRecord 顯示英雄榜對話框=null;
Game()
{
buttonPerson=new JButton(new ImageIcon("微笑臉.gif"));
雷陣=new MineSquare("中級",40,16,16,buttonPerson,記錄對話框);
buttonPerson.addActionListener(this);
con=getContentPane();
con.add(雷陣,BorderLayout.CENTER);
box=new JPanel();
box.setLayout(new GridLayout(1,3));
box.add(雷陣.count.textShowMine);
box.add(buttonPerson);
box.add(雷陣.time.textShowTime);
con.add(box,BorderLayout.NORTH);
setVisible(true);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
});
setBounds(100,50,360,380);
bar=new JMenuBar();
fileMenu=new JMenu("游戲");
初級=new JMenuItem("初級");
中級=new JMenuItem("中級");
高級=new JMenuItem("高級");
fileMenu.setMnemonic('G');
初級.setMnemonic('B');
中級.setMnemonic('I');
高級.setMnemonic('E');
掃雷英雄榜=new JMenuItem("掃雷英雄榜");
初級.setMnemonic('T');
fileMenu.add(初級);
fileMenu.add(中級);
fileMenu.add(高級);
fileMenu.add(掃雷英雄榜);
bar.add(fileMenu);
setJMenuBar(bar);
初級.addActionListener(this);
中級.addActionListener(this);
高級.addActionListener(this);
掃雷英雄榜.addActionListener(this);
hashtable=new Hashtable();
hashtable.put("初級","初級#"+999+"#匿名");
hashtable.put("中級","中級#"+999+"#匿名");
hashtable.put("高級","高級#"+999+"#匿名");
記錄對話框=new Record(this,hashtable);
記錄對話框.setGrade("高級");
if(!英雄榜.exists())
{
try{
FileOutputStream out=new FileOutputStream(英雄榜);
ObjectOutputStream object_out=new ObjectOutputStream(out);
object_out.writeObject(hashtable);
object_out.close();
out.close();
}
catch(IOException e)
{
}
}
顯示英雄榜對話框=new ShowRecord(this,hashtable);
validate();
}
public void newGame(String grade,int number,int rows,int cols,int w,int h)
{
buttonPerson.setIcon(new ImageIcon("微笑臉.gif"));
記錄對話框.setGrade(grade);
雷陣=new MineSquare(grade,number,rows,cols,buttonPerson,記錄對話框);
con.removeAll();
box.removeAll();
box.add(雷陣.count.textShowMine);
box.add(buttonPerson);
box.add(雷陣.time.textShowTime);
con.add(box,BorderLayout.NORTH);
con.add(雷陣,BorderLayout.CENTER);
setBounds(10,10,w,h);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==初級)
{
grade=1;
newGame("初級",10,8,8,180,220);
}
if(e.getSource()==中級)
{
grade=2;
newGame("中級",40,16,16,360,380);
}
if(e.getSource()==高級)
{
grade=3;
newGame("高級",99,22,22,500,520);
}
if(e.getSource()==掃雷英雄榜)
{
顯示英雄榜對話框.顯示記錄();
顯示英雄榜對話框.setVisible(true);
}
if(e.getSource()==buttonPerson)
{
if(grade==1)
{
newGame("初級",10,8,8,180,220);
}
if(grade==2)
{
newGame("中級",40,16,16,360,380);
}
if(grade==3)
{
newGame("高級",99,22,22,500,520);
}
}
}
public static void main(String args[])
{ new Game();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -