1.急求猜数字小游戏代码
急求猜数字小游戏代码
本人是猜喜JAVA语言爱好者,赠送你我的欢源积分兑换源码大全源码。
还是码猜安卓收银系统源码学学JAVA吧。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
class Guess extends JFrame implements ActionListener{
int rand;
JLabel label = new JLabel("Enter whole number:");
JLabel label_image = new JLabel( new ImageIcon(".gif"));
JTextField textfield = new JTextField();
JButton button_guess = new JButton("Guess");
JButton button_again = new JButton("Once again");
JPanel panel_north = new JPanel();
JPanel panel_center = new JPanel();
JPanel panel_north_middle = new JPanel();
TextArea textarea = new TextArea(null,喜欢java备忘录源码,,TextArea.SCROLLBARS_BOTH);
//---------------------------------------
Guess(){
this.setSize(,);
this.rand=(int)(Math.random()*);
Container face =this.getContentPane();
face.add(panel_north,"North");
face.add(panel_center);
panel_north.setLayout(new GridLayout(1,3,3,1));
panel_north.add(label);
panel_north.add(textfield);
panel_north.add(button_guess);
panel_north.add(button_again);
panel_center.add(textarea);
panel_center.add(label_image);
button_guess.addActionListener(this);
button_again.addActionListener(this);
this.setVisible(true);
}
//---------------------------------------------
public void actionPerformed(ActionEvent w){
try{
if(w.getSource()==button_guess){
String s=textfield.getText();
int x=Integer.parseInt(s);
if(x==rand){
textarea.append("Congratulate!\n");
}
else if(x>rand){
textarea.append("The number on the height side!\n");
}
else if(x<rand){
textarea.append("The number on the low side!\n");
}
textfield.setText("");
textfield.requestFocusInWindow();
}
else if(w.getSource()==button_again){
textarea.setText("");
rand=(int)(Math.random()*);
}
}catch(Exception e){ }
}
//-----------------------------------------------------------
public static void main(String arg[]){
new Guess().setDefaultLookAndFeelDecorated(true);
}
}