java猜数字代码有界面 java猜数字游戏代码界面( 四 )


{
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("恭喜,答对了! ");
} else
{
lbnum.setText(String
.valueOf(Integer.valueOf(lbnum.getText()) - 1));
if (Integer.valueOf(lbnum.getText()) == 0)
{
String str = "";
jttishi.setText("机会没有了!很遗憾");
for (int i = 0; ic.length; i++)
str += c[i];
tafo.append("超过限制次数,失败!" + "正确答案是:" + str);
start = false;
btn.setText("开始");
} else
jttishi.setText("输入四个数:");
}
}
if (s.equals("正确答案"))
{
if (!start)
{
jttishi.setText("还没开始呢!");
return;
}
String str = "";
for (int i = 0; ic.length; i++)
str += c[i];
tafo.append("正确答案是:" + str);
jttishi.setText("重新开始吧!");
start = false;
jisuan = false;
btn.setText("开始");
}
if (!start)
{
inputcishu.setEnabled(true);
} else
inputcishu.setEnabled(false);
if (s.equals("输入限制次数"))
{
while (true)
{
try
{
String str = JOptionPane.showInputDialog(this,
"输入小于15的整数数字:");
if (str == null)
return;
if (Integer.valueOf(str) = 15 Integer.valueOf(str) 0)
{
xianzhi=Integer.valueOf(str);
lbnum.setText(String.valueOf(xianzhi));
break;
} else
{
int i = JOptionPane.showConfirmDialog(this, "输入错误,重试?",
"", JOptionPane.YES_NO_OPTION);
if (i == 1)
break;

推荐阅读