java+猜字代码 java猜字母( 二 )


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("重玩"))
{
StringBuffer sb = new StringBuffer("0123456789");
for (int i = 0; ic.length; i++)
{
int n = (int) (Math.random() * sb.length());
c[i] = sb.charAt(n);
sb.deleteCharAt(n);
}
btn.setText("重玩");
start = true;
lbnum.setText(String.valueOf(xianzhi));
jisuan = false;
//System.out.println(c);
jttishi.setText("请输入四不重复的数:");
jtinput.setText("");
tafo.setText("");
}
if (s.compareTo("0") = 0s.compareTo("9") = 0)
{
jisuan = false;
if (!start)
jttishi.setText("点击开始!");
else
{
if (jtinput.getText().length()4)
{
if (jtinput.getText().indexOf(s)0)
{
jtinput.setText(jtinput.getText() + s);
if (jtinput.getText().length()4)
jttishi.setText("还差"
+ (4 - jtinput.getText().length()) + "个数");
else
{
jttishi.setText("输入正确,点击确定");
jisuan = true;
}
} else
jttishi.setText("不能输入重复的数");
} else
{
jttishi.setText("不能超过四个数,点击确定");
jisuan = true;
}
}
}
if (s.equals("退格")start)
{
if (jtinput.getText().length()0)
{
jtinput.setText(jtinput.getText().substring(0,
jtinput.getText().length() - 1));
jttishi.setText("还差" + (4 - jtinput.getText().length()) + "个数");
}
jisuan = false;
}
if (s.equals("确定"))
{
if (!start)
{
jttishi.setText("还没开始呢!");
return;
}
if (!jisuan)
{
jttishi.setText("输入不正确!");
return;
}
int numa = 0, numb = 0;
char[] c1 = jtinput.getText().toCharArray();
// System.out.println(c1);
for (int i = 0; ic1.length; i++)
{
for (int j = 0; jc.length; j++)
{
if (c1[i] == c[j]i != j)
{
numb++;
}
if (c1[i] == c[j]i == j)
{
numa++;
}
}
}
tafo.append(jtinput.getText() + "\t" + numa + "A" + numb + "B"
+ "\n");
jtinput.setText("");
jisuan = false;
if (numa == 4)
{
jttishi.setText("答对了 , 再来一局吧!");
start = false;
btn.setText("开始");
tafo.append("恭喜,答对了! ");

推荐阅读