?? cleanmine.java
字號:
package cleanmine;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class CleanMine extends JFrame implements ActionListener{
// private JFrame frame ;
private JMenu file ,help;
private JLabel label1,label2;
private JLabel time;
public static JLabel remainMine;
private JButton restart;
private int col,row,mine;
private JPanel center;
public CleanMine(){
// frame= new JFrame("掃雷");
label1= new JLabel("剩余地雷:");
label2 = new JLabel("所用時間:");
remainMine = new JLabel("10");
time = new JLabel("0");
restart = new JButton("重新開始");
restart.addActionListener(this);
JMenuBar bar= new JMenuBar();;
file = new JMenu("游戲");
help = new JMenu("幫助");
JMenuItem item;
ButtonGroup bg = new ButtonGroup();
file.add(item=new JMenuItem("開始"));item.addActionListener(this);
file.addSeparator();
file.add(item=new JCheckBoxMenuItem ("低級趣味",true));bg.add(item);item.addActionListener(this);
file.add(item=new JCheckBoxMenuItem ("略有品位"));bg.add(item);item.addActionListener(this);
file.add(item=new JCheckBoxMenuItem ("極有品位"));bg.add(item);item.addActionListener(this);
file.add(item=new JCheckBoxMenuItem ("沒有品位"));bg.add(item);item.addActionListener(this);
file.addSeparator();
file.add(item=new JMenuItem("退出"));item.addActionListener(this);
help.add(item=new JMenuItem("幫組"));item.addActionListener(this);
file.addSeparator();
help.add(item=new JMenuItem("關于"));item.addActionListener(this);
bar.add(file);
bar.add(help);
this.setJMenuBar(bar);
init();
}
public void init(){
JPanel north = new JPanel();
// north.setLayout(new FlowLayout());
north.add(label1);
north.add(remainMine);
north.add(restart);
north.add(label2);
north.add(time);
this.add(north, BorderLayout.NORTH);
this.row=9;
this.col=9;
this.mine=10;
restart();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new Thread(){
public void run(){
while(Integer.parseInt(remainMine.getText())>0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
time.setText((Integer.parseInt(time.getText())+1)+"");
}
}
}.start();
}
public void restart(){
if(center!=null){
this.remove(center);
}
center=new AllButtonPanel2(row,col,mine);
this.add(center,BorderLayout.CENTER);
this.remainMine.setText(mine+"");
this.time.setText("0");
this.setSize(col*30,row*30+10);
this.setResizable(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("低級趣味")){
this.row= 9;
this.col= 9;
this.mine = 10;
restart();
return;
}
if(e.getActionCommand().equals("略有品位")){
this.row = 16;
this.col = 16;
this.mine= 40;
restart();
return;
}
if(e.getActionCommand().equals("極有品位")){
this.row = 25;
this.col= 30;
this.mine= 70;
restart();
return;
}
if(e.getActionCommand().equals("沒有品位")){
this.row = 45;
this.col= 44;
this.mine= 200;
restart();
return;
}
if(e.getActionCommand().equals("重新開始")){
restart();
return;
}
}
public static void main(String[] args) {
new CleanMine();
// System.out.println(AllButtonPanel.index);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -