?? jmine.java
字號:
rows = dlg.getRows();
columns = dlg.getColumns();
mines = dlg.getMines();
minePanel.setGameLevel(rows, columns, mines);
if (isStandalone) {
if (frame != null) {
//frame.pack();
Utils.packPlaceShow(frame);
}
}
else {
setSize(getPreferredSize());
validate();
}
}
});
miMark.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
minePanel.isMark = state;
mineProps.isMark = state;
}
});
miColor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
minePanel.isColor = state;
mineProps.isColor = state;
// 暫未實現
}
});
miSound.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
minePanel.isSound = state;
mineProps.isSound = state;
// 實現不完全,只能發出單調的beep聲
}
});
miTopList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showTopListDialog();
}
});
if (isStandalone) {
miExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
exitApp();
}
});
}
else {
miExit.setEnabled(false);
}
miAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showAboutDialog();
}
});
// 組裝菜單
mFile.add(miNew);
mFile.addSeparator();
mFile.add(miLowRank);
mFile.add(miMiddleRank);
mFile.add(miHighRank);
mFile.add(miCustomRank);
mFile.addSeparator();
mFile.add(miMark);
mFile.add(miColor);
mFile.add(miSound);
mFile.addSeparator();
mFile.add(miTopList);
mFile.addSeparator();
mFile.add(miExit);
mHelp.add(miContent);
mHelp.add(miSearch);
mHelp.add(miShowHelp);
mHelp.addSeparator();
mHelp.add(miAbout);
menuBar.add(mFile);
menuBar.add(mHelp);
// 重新設置菜單的字體
// Font font = new Font(mFile.getFont().getName(), Font.PLAIN, 12);
mFile.setFont(defaultFont);
mHelp.setFont(defaultFont);
miNew.setFont(defaultFont);
miLowRank.setFont(defaultFont);
miMiddleRank.setFont(defaultFont);
miHighRank.setFont(defaultFont);
miCustomRank.setFont(defaultFont);
miMark.setFont(defaultFont);
miColor.setFont(defaultFont);
miSound.setFont(defaultFont);
miTopList.setFont(defaultFont);
miExit.setFont(defaultFont);
miContent.setFont(defaultFont);
miSearch.setFont(defaultFont);
miShowHelp.setFont(defaultFont);
miAbout.setFont(defaultFont);
// 返回菜單欄
return menuBar;
}
/**
* Creates an icon from an image contained in the "images" directory.
*/
public ImageIcon createImageIcon(String filename, String description) {
String path = "/images/" + filename;
return new ImageIcon(getClass().getResource(path), description);
}
/**
* 退出應用程序
*/
public void exitApp() {
// 保存屬性
if (isStandalone) {
mineProps.save();
}
stop();
destroy();
if (frame != null)
frame.dispose();
if (isStandalone)
System.exit(0);
}
/**
* 顯示“掃雷英雄榜”對話框
*/
public void showTopListDialog() {
TopListDialog dlg = new TopListDialog(this);
//dlg.show();
Utils.packCenterShow(frame, dlg);
}
/**
* 顯示“關于”對話框
*/
public void showAboutDialog() {
JDialog dlg = new AboutDialog(this);
//dlg.show();
Utils.packCenterShow(frame, dlg);
}
/** 作為本Java Application的主方法 */
public static void main(String[] args) {
final JMine jMine = new JMine();
jMine.isStandalone = true;
/*final */JFrame frame = new JFrame("掃雷");
jMine.frame = frame;
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
jMine.exitApp();
}
public void windowDeiconified(WindowEvent e) {
jMine.start();
}
public void windowIconified(WindowEvent e) {
jMine.stop();
}
});
ImageIcon imgIcon = jMine.createImageIcon("mine.png", "地雷圖標");
frame.setIconImage(imgIcon.getImage());
frame.getContentPane().add(jMine, BorderLayout.CENTER);
jMine.init();
jMine.start();
// frame.setUndecorated(true);
// frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
// SwingUtilities.updateComponentTreeUI(frame.getRootPane());
// 包裝/縮緊窗口
frame.pack();
// 使窗口居于屏幕中央
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2,
(d.height - frame.getSize().height) / 2);
// 顯示窗口
frame.setVisible(true);
}
//static initializer for setting look & feel
static {
try {
String vers = System.getProperty("java.version");
if (vers.compareTo("1.4") < 0) {
System.out.println("JMine must be run with a 1.4 or higher version JVM!!!");
System.exit(0);
}
} catch (Throwable t) {
System.out.println("uncaught exception: " + t);
t.printStackTrace();
}
// 載入屬性
mineProps = new MineProps();
mineProps.load();
// 決定外觀感覺
try {
// javax.swing.plaf.metal.MetalLookAndFeel
if (mineProps.lookAndFeel.equals(MineProps.METAL)) {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
else if (mineProps.lookAndFeel.equals(MineProps.WINDOZ)) {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
else if (mineProps.lookAndFeel.equals(MineProps.MOTIF)) {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
else {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} catch (Exception exc) {
System.err.println("載入界面樣式失敗:" + exc);
}
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -