📄 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 + -