inputcishu.setEnabled(false);
systemmenu.add(inputsecret);
systemmenu.add(inputcishu);
systemmenu.add(quit);
quit.addActionListener(this);
help.addActionListener(this);
helpmenu.add(help);
mb.add(filemenu);
mb.add(systemmenu);
mb.add(helpmenu);
this.setMenuBar(mb);
Container c = this.getContentPane();
BorderLayout b = new BorderLayout();
b.setVgap(10);
c.setLayout(b);
settextpanel();
c.add(textpanel, BorderLayout.NORTH);
setbuttonpanel();
setfopanel();
setdownpanel();
c.add(downpanel, BorderLayout.CENTER);
this.setSize(680,350);
//this.setResizable(false);
//this.pack();
this.setVisible(true);
}
void settextpanel()
{
textpanel = new JPanel();
textpanel.setLayout(new FlowLayout());
lbinput = new JLabel("输入:");
jtinput = new JTextField("", 10);
jtinput.setEditable(false);
jttishi = new JTextField(30);
lbnum = new JLabel("8");
lbnum0 = new JLabel("剩余次数:");
lbtishi = new JLabel("提示:");
jttishi.setEditable(false);
textpanel.add(lbinput);
textpanel.add(jtinput);
textpanel.add(lbtishi);
textpanel.add(jttishi);
textpanel.add(lbnum0);
textpanel.add(lbnum);
}
void setbuttonpanel()
{
String[] str =
{ "7", "8", "9", "4", "5", "6", "1", "2", "3", "确定", "0", "退格" };
buttonpanel = new JPanel();
buttonpanel.setLayout(new GridLayout(4, 3, 4, 8));
for (int i = 0; istr.length; i++)
{
btn = new JButton(str[i]);
btn.addActionListener(this);
buttonpanel.add(btn);
}
}
void setfopanel()
{
JButton btnright = new JButton("正确答案");
JPanel p = new JPanel();
btnright.addActionListener(this);
fopanel = new JPanel();
fopanel.setLayout(new BorderLayout());
btn = new JButton("开始");
btn.addActionListener(this);
tafo = new JTextArea(15,12);
p.setLayout(new GridLayout(1, 2));
p.add(btn);
p.add(btnright);
fopanel.add(p, BorderLayout.NORTH);
tafo.setEditable(false);
fopanel.add(tafo, BorderLayout.CENTER);
}
void setdownpanel()
{
downpanel = new JPanel();
downpanel.setLayout(new GridLayout(1, 2, 30, 0));
downpanel.add(buttonpanel);
downpanel.add(fopanel);
}
public static void main(String[] args)
{
new caishuzi();
}
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (s.equals("退出"))
{
int i = JOptionPane.showConfirmDialog(this, "确认退出?", "",
JOptionPane.YES_NO_OPTION);
//System.out.println(i);
if (i == 0)
{
System.exit(0);
}
}
if (s.equals("帮助"))
{
JOptionPane.showMessageDialog(this,
"猜数字游戏,可以输入限制次数,密码为123,\n在菜单:系统——输入密码 中输入!");
}
if (s.equals("输入密码"))
{
while (true)
{
String inputValuehttps://www.04ip.com/post/= "";
inputValue = https://www.04ip.com/post/JOptionPane.showInputDialog(this,"输入密码");
// System.out.println(inputValue);
if (inputValue =https://www.04ip.com/post/= null)
return;
if (inputValue.equals(strsecret))
{
jinru = true;
jttishi.setText("密码正确,点击开始");
inputsecret.setEnabled(false);
break;
} else
{
int i = JOptionPane.showConfirmDialog(this, "密码错误,重新输入?",
"", JOptionPane.YES_NO_OPTION);
if (i == 1)
break;
}
}
}
if (!jinru)
{
jttishi.setText("请输入密码:");
return;
}
if (s.equals("开始") || s.equals("重玩"))
推荐阅读
- 安卓平板电脑背光键盘,安卓平板电脑背光键盘怎么打开
- 视频号怎么认证歌手身份,视频号怎么认证歌手身份证
- mac即时战略单机游戏,即时战略pc单机游戏
- 积攒星光的直播是什么,积攒星光的直播是什么平台
- php十万条数据遍历 php循环10万数据
- jquery替换非法字符串,jQuery字符串转日期
- 怎么能把微信的视频号关掉,怎么能把微信的视频号关掉呢
- 如何识别新媒体运营能力,怎么看新媒体运营
- 数据提交方式php 提交表单数据有哪几种方法,php如何获取表单提交的数据