java小游戏代码24点的简单介绍( 四 )


y++ ;
result.add(tempS + "=24");
if (y == x) {
return result;
}
}
}
}
}
}
return result;
}
public static boolean check(String param1) {
Pattern pattern = Pattern.compile("[0-9]{4}");
Matcher matcher = pattern.matcher((CharSequence)param1);
boolean result = matcher.matches();
if (result == false) {
JOptionPane.showMessageDialog(null, "please enter correct number");
return false;
} else {
return true;
}
}
public static boolean check1(String param2) {
if(param2 == null){
JOptionPane.showMessageDialog(null, "please enter correct number");
return false;
}
Pattern pattern = Pattern.compile("[0-9]{0,99}");
Matcher matcher = pattern.matcher((CharSequence)param2);
boolean result = matcher.matches();
if (result == false) {
JOptionPane.showMessageDialog(null, "please enter correct number");
return false;
} else {
return true;
}
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(81, 275, 110, 54);
jButton.setText("calculate");
jButton.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
if(e.getKeyCode()==10){
if (check(jTextField.getText())
check1(jTextField1.getText())) {
if(!jTextField1.getText().equals("0")){
List b = test(jTextField.getText(), Integer
.parseInt(jTextField1.getText()));
String temp = "";
for (int i = 0; ib.size(); i++ ) {
temp = temp + b.get(i) + "\n";
}
if (b.size() == 0) {
jTextArea.setText("NO RESULT");
} else {
jTextArea.setText(temp);
}
}else{
JOptionPane.showMessageDialog(null, "please enter correct number");
}
}
}
}
});
jButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
if (check(jTextField.getText())
check1(jTextField1.getText())) {
if(!jTextField1.getText().equals("0")){
List b = test(jTextField.getText(), Integer
.parseInt(jTextField1.getText()));
String temp = "";
for (int i = 0; ib.size(); i++ ) {
temp = temp + b.get(i) + "\n";
}
if (b.size() == 0) {
jTextArea.setText("NO RESULT");
} else {
jTextArea.setText(temp);
}
}else{
JOptionPane.showMessageDialog(null, "please enter correct number");
}
}
}
});
}
return jButton;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(267, 238, 216, 124);
jScrollPane.setViewportView(getJTextArea());
}
return jScrollPane;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(40, 148, 42, 28);
jButton1.setText("1");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
jTextField.setText(jTextField.getText()+"1");
}
});
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(90, 148, 42, 28);
jButton2.setText("2");

推荐阅读