java对话框游戏代码 java对话框游戏代码是什么( 三 )


private void restart() {
// 记录时间
recordTime();
txtGuessRecord.append("游戏开始\n");
// 状态清零
current_time = 0;
btnGuess.setEnabled(true);
isRight = false;
current_puzzle = createRandomChar(cbType.getSelectedIndex());
setText('?');
showInfo();
}
// 停止游戏
private void stop() {
btnGuess.setEnabled(false);
setText(current_puzzle);
// 正确的情况
if (isRight) {
String info = String.format("你用了%d次猜对了\n", current_time);
txtGuessRecord.append(info);
} else
// 超过次数的情况
txtGuessRecord.append("你输了\n");
recordTime();
txtGuessRecord.append("游戏结束\n");
}
// 显示游戏信息
private void showInfo() {
String info = String.format("已经猜了%d次, 还剩 %d次 ", current_time,
MAX_TIME - current_time);
lblInfo.setText(info);
}
// 清空记录框
private void clear() {
txtGuessRecord.setText("");
}
private void save() {
// 尚未实现
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MainFrame();
}
});
}
// 正则格式类, 文本框匹配用
class RegexFormatter extends DefaultFormatter {
/**
*
*/
private static final long serialVersionUID = 1L;
private Pattern pattern;
private Matcher matcher;
public RegexFormatter() {
super();
}
public RegexFormatter(String pattern) throws PatternSyntaxException {
this();
setPattern(Pattern.compile(pattern));
}
public RegexFormatter(Pattern pattern) {
this();
setPattern(pattern);
}
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
public Pattern getPattern() {
return pattern;
}
protected void setMatcher(Matcher matcher) {
this.matcher = matcher;
}
protected Matcher getMatcher() {
return matcher;
}
public Object stringToValue(String text) throws ParseException {
Pattern pattern = getPattern();
if (pattern != null) {
Matcher matcher = pattern.matcher(text);
if (matcher.matches()) {
setMatcher(matcher);
return super.stringToValue(text);
}
throw new ParseException("Pattern did not match", 0);
}
return text;
}
}
}
java对话框游戏代码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于java对话框游戏代码是什么、java对话框游戏代码的信息别忘了在本站进行查找喔 。

推荐阅读