?? jmine.java
字號:
/*
* JMine.java 1.0 2003-06-25
*
* Copyleft (c) 2003 RatKing.
*/
/*
<applet archive="JMine.jar" code="jmine.JMine.class" width="500" height="400">
</applet>
*/
package jmine;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* 掃雷游戲
*
* @author <a href="ratking@ynet.com">RatKing</a>
* @version 1.0
*/
public class JMine extends JApplet {
public static final Font defaultFont = new Font("Dialog", Font.PLAIN, 12);
public static MineProps mineProps;
/** 本程序以Java Application模式獨立運行則為true,以Applet模式運行則為false */
public boolean isStandalone = false;
public JMine instance = null;
public JFrame frame = null;
private JMenuBar menubar;
private MinePanel minePanel;
public int gameLevel;
/** Construct the JMine applet */
public JMine() {
this(mineProps.gameLevel);
}
public JMine(int gameLevel) {
this.gameLevel =gameLevel;
}
/** Initialize the applet */
public void init() {
instance = this;
//Component initialization
// 添加菜單欄
JMenuBar menubar = createMenuBar();
setJMenuBar(menubar);
// 添加總面板
minePanel = new MinePanel(this, gameLevel);
minePanel.isMark = mineProps.isMark;
minePanel.isColor = mineProps.isColor;
minePanel.isSound = mineProps.isSound;
//getRootPane().setDefaultButton(minePanel.faceButton);
getContentPane().add(minePanel, BorderLayout.CENTER);
}
/** Start the applet */
public void start() {
minePanel.resume();
if (!isStandalone) {
showStatus(getAppletInfo());
}
}
/** Stop the applet */
public void stop() {
minePanel.pause();
}
/** Destroy the applet */
public void destroy() {
}
/** Get a parameter value */
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/** Get Applet information */
public String getAppletInfo() {
return "JMine v1.0 by RatKing 2003.06.25";
}
/** Get parameter info */
public String[][] getParameterInfo() {
return null;
}
/**
* 創(chuàng)建菜單欄
* @return 創(chuàng)建的菜單欄
*/
public JMenuBar createMenuBar() {
// 定義菜單欄
JMenuBar menuBar = new JMenuBar();
// 定義主菜單
JMenu mFile = new JMenu("游戲(G)");
JMenu mHelp = new JMenu("幫助(H)");
// 定義菜單項
JMenuItem miNew = new JMenuItem("開局(N)");
JRadioButtonMenuItem miLowRank = new JRadioButtonMenuItem("初級(B)", true);
JRadioButtonMenuItem miMiddleRank = new JRadioButtonMenuItem("中級(I)");
JRadioButtonMenuItem miHighRank = new JRadioButtonMenuItem("高級(E)");
JRadioButtonMenuItem miCustomRank = new JRadioButtonMenuItem("自定義(C)...");
JCheckBoxMenuItem miMark = new JCheckBoxMenuItem("標(biāo)記(?)(M)", true);
JCheckBoxMenuItem miColor = new JCheckBoxMenuItem("顏色(L)", true);
JCheckBoxMenuItem miSound = new JCheckBoxMenuItem("聲音(S)", true);
JMenuItem miTopList = new JMenuItem("掃雷英雄榜(T)...");
JMenuItem miExit = new JMenuItem("退出(X)");
JMenuItem miContent = new JMenuItem("目錄(C)");
JMenuItem miSearch = new JMenuItem("查找?guī)椭黝}(S)...");
JMenuItem miShowHelp= new JMenuItem("使用幫助(H)");
JMenuItem miAbout = new JMenuItem("關(guān)于掃雷(A)...");
miLowRank.setSelected(mineProps.gameLevel == MinePanel.LOW_LEVEL);
miMiddleRank.setSelected(mineProps.gameLevel == MinePanel.MIDDLE_LEVEL);
miHighRank.setSelected(mineProps.gameLevel == MinePanel.HIGH_LEVEL);
miCustomRank.setSelected(mineProps.gameLevel == MinePanel.CUSTOM_LEVEL); // 永遠(yuǎn)不可能發(fā)生
miMark.setSelected(mineProps.isMark);
miColor.setSelected(mineProps.isColor);
miSound.setSelected(mineProps.isSound);
// 指定助記鍵、快捷鍵
mFile.setMnemonic(KeyEvent.VK_G);
mHelp.setMnemonic(KeyEvent.VK_H);
miNew.setMnemonic(KeyEvent.VK_N);
miNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
miLowRank.setMnemonic(KeyEvent.VK_B);
miMiddleRank.setMnemonic(KeyEvent.VK_I);
miHighRank.setMnemonic(KeyEvent.VK_E);
miCustomRank.setMnemonic(KeyEvent.VK_C);
miMark.setMnemonic(KeyEvent.VK_M);
miColor.setMnemonic(KeyEvent.VK_L);
miSound.setMnemonic(KeyEvent.VK_S);
miTopList.setMnemonic(KeyEvent.VK_T);
miExit.setMnemonic(KeyEvent.VK_X);
miContent.setMnemonic(KeyEvent.VK_C);
miContent.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
miSearch.setMnemonic(KeyEvent.VK_S);
miShowHelp.setMnemonic(KeyEvent.VK_H);
miAbout.setMnemonic(KeyEvent.VK_A);
// 將4個游戲級別單選菜單歸為一組
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(miLowRank);
buttonGroup.add(miMiddleRank);
buttonGroup.add(miHighRank);
buttonGroup.add(miCustomRank);
// 設(shè)置菜單項對應(yīng)的功能
miNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
minePanel.replay();
if (!isStandalone) {
setSize(getPreferredSize());
validate();
}
else if (frame != null) {
frame.pack();
}
}
});
miLowRank.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
minePanel.setGameLevel(MinePanel.LOW_LEVEL);
mineProps.gameLevel = MinePanel.LOW_LEVEL;
if (isStandalone) {
if (frame != null) {
//frame.pack();
Utils.packPlaceShow(frame);
}
}
else {
setSize(getPreferredSize());
validate();
}
}
});
miMiddleRank.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
minePanel.setGameLevel(MinePanel.MIDDLE_LEVEL);
mineProps.gameLevel = MinePanel.MIDDLE_LEVEL;
if (isStandalone) {
if (frame != null) {
//frame.pack();
Utils.packPlaceShow(frame);
}
}
else {
setSize(getPreferredSize());
validate();
}
}
});
miHighRank.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
minePanel.setGameLevel(MinePanel.HIGH_LEVEL);
mineProps.gameLevel = MinePanel.HIGH_LEVEL;
if (isStandalone) {
if (frame != null) {
//frame.pack();
Utils.packPlaceShow(frame);
}
}
else {
setSize(getPreferredSize());
validate();
}
}
});
miCustomRank.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int rows = minePanel.getMineRows();
int columns = minePanel.getMineColumns();
int mines = minePanel.getTotalMines();
CustomDialog dlg = new CustomDialog(frame);
dlg.setRows(rows);
dlg.setColumns(columns);
dlg.setMines(mines);
//dlg.show();
Utils.packCenterShow(frame, dlg);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -