?? customdialog.java
字號:
package nicholas.game.mine;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CustomDialog extends JDialog implements ActionListener {
private JTextField widthField;
private JTextField heightField;
private JTextField mineField;
private JButton confirmButton;
private JButton cancelButton;
private static LevelInfo level;
public CustomDialog(Frame frame, LevelInfo levelInfo) {
super(frame,"自定義雷區",true);
getContentPane().setLayout(null);
JLabel tempLabel = new JLabel("高度:");
tempLabel.setBounds(10,10,30,20);
heightField = new JTextField(""+levelInfo.getXBound());
heightField.setBounds(50,10,40,20);
getContentPane().add(tempLabel,null);
getContentPane().add(heightField,null);
tempLabel = new JLabel("寬度:");
tempLabel.setBounds(10,40,30,20);
widthField = new JTextField(""+levelInfo.getYBound());
widthField.setBounds(50,40,40,20);
getContentPane().add(tempLabel,null);
getContentPane().add(widthField,null);
tempLabel = new JLabel("雷數:");
tempLabel.setBounds(10,70,30,20);
mineField = new JTextField(""+levelInfo.getMineCount());
mineField.setBounds(50,70,40,20);
getContentPane().add(tempLabel,null);
getContentPane().add(mineField,null);
confirmButton = new JButton("確定");
confirmButton.addActionListener(this);
confirmButton.setBounds(100,10,60,25);
getContentPane().add(confirmButton,null);
cancelButton = new JButton("取消");
cancelButton.addActionListener(this);
cancelButton.setBounds(100,45,60,25);
getContentPane().add(cancelButton,null);
setSize(180,137);
setLocationRelativeTo(frame);
setResizable(false);
show();
}
public void actionPerformed(ActionEvent e) {
level = null;
if(e.getSource()==confirmButton) {
int x = Integer.parseInt(heightField.getText());
int y = Integer.parseInt(widthField.getText());
int m = Integer.parseInt(mineField.getText());
level = new LevelInfo(x,y,m);
}
dispose();
}
public static LevelInfo getUserLevel(JFrame frame, LevelInfo levelInfo) {
CustomDialog dialog = new CustomDialog(frame, levelInfo);
return level;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -