?? toplistdialog.java
字號:
/*
* TopListDialog.java 1.0 2003-06-25
*
* Copyleft (c) 2003 RatKing.
*/
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 TopListDialog extends JDialog {
private JMine jmine;
GridLayout gridLayout = new GridLayout(3, 0);
JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 5));
JPanel levelPanel = new JPanel(gridLayout);
JPanel timePanel = new JPanel(gridLayout);
JPanel namePanel = new JPanel(gridLayout);
JPanel buttonPanel = new JPanel();
JLabel gameLevelLabel1 = new JLabel("初級:");
JLabel gameLevelLabel2 = new JLabel("中級:");
JLabel gameLevelLabel3 = new JLabel("高級:");
JLabel timeLabel1 = new JLabel();
JLabel timeLabel2 = new JLabel();
JLabel timeLabel3 = new JLabel();
JLabel nameLabel1 = new JLabel();
JLabel nameLabel2 = new JLabel();
JLabel nameLabel3 = new JLabel();
JButton resetButton = new JButton("重新計分(R)");
JButton okButton = new JButton("確定(O)");
private MineProps mineProps = JMine.mineProps;
public TopListDialog(JMine jmine) {
this(jmine, jmine.frame);
}
public TopListDialog(JMine jmine, Frame owner) {
super(owner, "掃雷英雄榜", true);
this.jmine = jmine;
init();
}
private void init() {
timeLabel1.setText(mineProps.getTime(MinePanel.LOW_LEVEL) + " 秒");
timeLabel2.setText(mineProps.getTime(MinePanel.MIDDLE_LEVEL) + " 秒");
timeLabel3.setText(mineProps.getTime(MinePanel.HIGH_LEVEL) + " 秒");
timeLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
timeLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
timeLabel3.setHorizontalAlignment(SwingConstants.RIGHT);
nameLabel1.setText(mineProps.getName(MinePanel.LOW_LEVEL));
nameLabel2.setText(mineProps.getName(MinePanel.MIDDLE_LEVEL));
nameLabel3.setText(mineProps.getName(MinePanel.HIGH_LEVEL));
//JPanel p1 = new JPanel(new GridLayout(3, 3, 10, 2));
//JPanel p2 = new JPanel();
//p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
okButton.setMnemonic(KeyEvent.VK_O);
resetButton.setMnemonic(KeyEvent.VK_R);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//measure();
dispose();
}
});
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reset();
}
});
// 添加提示信息
centerPanel.setToolTipText("<html><font size=3>對于每級游戲(初級、中級、高級),"
+ "<br>顯示玩家的最短游戲時間,以及玩家的名稱。</font></html>");
resetButton.setToolTipText("<html><font size=3>清除當前的高分。</font></html>");
okButton.setToolTipText("<html><font size=3>關閉該對話框并保存所作的更改。</font></html>");
// 設置字體
Font font = JMine.defaultFont;
gameLevelLabel1.setFont(font);
gameLevelLabel2.setFont(font);
gameLevelLabel3.setFont(font);
timeLabel1.setFont(font);
timeLabel2.setFont(font);
timeLabel3.setFont(font);
nameLabel1.setFont(font);
nameLabel2.setFont(font);
nameLabel3.setFont(font);
resetButton.setFont(font);
okButton.setFont(font);
// 開始組裝
levelPanel.add(gameLevelLabel1);
levelPanel.add(gameLevelLabel2);
levelPanel.add(gameLevelLabel3);
timePanel.add(timeLabel1);
timePanel.add(timeLabel2);
timePanel.add(timeLabel3);
namePanel.add(nameLabel1);
namePanel.add(nameLabel2);
namePanel.add(nameLabel3);
centerPanel.add(levelPanel);
centerPanel.add(timePanel);
centerPanel.add(namePanel);
buttonPanel.add(resetButton);
buttonPanel.add(okButton);
JPanel contentPane = (JPanel) getContentPane();
contentPane.setBorder(BorderFactory.createEmptyBorder(20, 15, 10, 15));
contentPane.add(centerPanel, BorderLayout.CENTER);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
getRootPane().setDefaultButton(okButton); // 好像不靈! Bug?
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setResizable(false);
pack();
okButton.requestFocus(); // 這個方法靈!可以使“確定”按鈕成為默認按鈕
}
public void reset() {
mineProps.resetTopList();
timeLabel1.setText(mineProps.getTime(MinePanel.LOW_LEVEL) + " 秒");
timeLabel2.setText(mineProps.getTime(MinePanel.MIDDLE_LEVEL) + " 秒");
timeLabel3.setText(mineProps.getTime(MinePanel.HIGH_LEVEL) + " 秒");
nameLabel1.setText(mineProps.getName(MinePanel.LOW_LEVEL));
nameLabel2.setText(mineProps.getName(MinePanel.MIDDLE_LEVEL));
nameLabel3.setText(mineProps.getName(MinePanel.HIGH_LEVEL));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -