📄 localgameinitdialog.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* this class will show dialog, it sets up the local game
*
*/
class LocalGameInitDialog extends JDialog
{
JLabel lb1 = new JLabel("请输入黑色玩家姓名:");
JLabel lb2 = new JLabel("请输入白色玩家姓名:");
JTextField tf1 = new JTextField(10);
JTextField tf2 = new JTextField(10);
JButton bn1 = new JButton("确定");
JButton bn2 = new JButton("取消");
JTextField tf = new JTextField(10);
boolean dialogResult;
public int totalSeconds;
public LocalGameInitDialog(JFrame parent, int w, int h)
{
super(parent, "初始化本地游戏", true);
setSize(w, h);
setLayout(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new GridLayout(3, 2));
p.add(lb1);
p.add(tf1);
p.add(lb2);
p.add(tf2);
p.add(new JLabel("下棋总时间"));
p.add(tf);
tf.setText("600");
add("North", p);
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(bn1);
p1.add(bn2);
add("South", p1);
bn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try{
totalSeconds = Integer.parseInt(tf.getText());
dialogResult = true;
}
catch(NumberFormatException ex)
{
System.out.println("Parse Integer Error!");
}
finally{
setVisible(false);
}
}
});
bn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
dialogResult = false;
setVisible(false);
}
});
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{setVisible(false);}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -