在百度上回答的問題,還不錯(cuò)啊, 我能做出來,別人也做出來了,不過還是學(xué)到點(diǎn)東西的,呵呵,下午應(yīng)該繼續(xù)學(xué)習(xí)GUI編程,老師讓我看那個(gè)java jdk上的demo,我覺得好難啊, 看了一上午,還是沒什么頭緒,三維的東西很難搞明白,有空再弄吧,
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math.*;
public class bb extends Frame implements ActionListener ,WindowListener
{ TextField tf1,tf2;
Label lb1,lb3,lb4;
Button but1,but2;
Panel p1,p2,p3;
double a,w,cc;
String s ,d;
String qq =null;
bb ()
{
Frame ff=new Frame("這是一個(gè)程序");
ff.setLayout(new BorderLayout());
but1=new Button("獲得1-100之間的隨機(jī)數(shù)");
tf1=new TextField(15);
lb1=new Label("請輸入你的猜測:");
tf2=new TextField(15);
//lb2=new Label("單擊確定按鈕");
but2=new Button("確定");
lb3=new Label("反饋信息:");
lb4=new Label("無反饋信息");
p1=new Panel();
p2=new Panel();
p3=new Panel();
but1.addActionListener(this);
but2.addActionListener(this);
p1.add(but1);
p1.add(tf1);
p2.add(lb1);
p2.add(tf2);
p2.add(but2);
p3.add(lb3);
p3.add(lb4);
ff.add("North",p1);
ff.add("Center",p2);
ff.add("South",p3);
ff.setSize(500,500);
ff.setVisible(true);
ff.addWindowListener(this);
ff.addWindowListener(this);
//ff.validate();
}
public void init()
{
this.add(but1);
this.add(tf1);
this.add(lb1);
this.add(tf2);
this.add(lb3);
this.add(but2);
this.add(lb4);
but1.addActionListener(this);
but2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
//TextField tf=(TextField)(e.getSource());
if( e.getSource()==but1){
a=Math.random();
//System.out.println(a);
double b =a*100;
int c=(int)b;
cc=c;
d=String.valueOf(cc);
tf1.setText(d);
}
if (e.getSource().equals(but2))
{
s=null;
s=tf2.getText();
String q=s;
if(s.length()==0){
s=qq;
System.out.println("現(xiàn)在你的值是"+qq+"不要輸入空值!");
}
tf2.setText("");
w=Integer.parseInt(s);
qq=s;
if (cc>w)
{
lb4.setText("笨蛋,猜小了你");
}
if (cc {
lb4.setText("猜大了,笨的跟豬一樣,!!嘎嘎");
}
if(cc==w)
{
if(q==null)
lb4.setText("The textfield is empty!");
lb4.setText("還好,你猜對(duì)了,要不要接著挨罵了!");
}
}
}
public void windowOpened(WindowEvent e)
{
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowClosed(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowActivated(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{
}
public static void main(String[] args)
{
bb f = new bb ();
}
}
Tags - 百度 , java , gui
文章來源:http://www.tt-shopping.com/kevinlau/read.php/117.htm
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math.*;
public class bb extends Frame implements ActionListener ,WindowListener
{ TextField tf1,tf2;
Label lb1,lb3,lb4;
Button but1,but2;
Panel p1,p2,p3;
double a,w,cc;
String s ,d;
String qq =null;
bb ()
{
Frame ff=new Frame("這是一個(gè)程序");
ff.setLayout(new BorderLayout());
but1=new Button("獲得1-100之間的隨機(jī)數(shù)");
tf1=new TextField(15);
lb1=new Label("請輸入你的猜測:");
tf2=new TextField(15);
//lb2=new Label("單擊確定按鈕");
but2=new Button("確定");
lb3=new Label("反饋信息:");
lb4=new Label("無反饋信息");
p1=new Panel();
p2=new Panel();
p3=new Panel();
but1.addActionListener(this);
but2.addActionListener(this);
p1.add(but1);
p1.add(tf1);
p2.add(lb1);
p2.add(tf2);
p2.add(but2);
p3.add(lb3);
p3.add(lb4);
ff.add("North",p1);
ff.add("Center",p2);
ff.add("South",p3);
ff.setSize(500,500);
ff.setVisible(true);
ff.addWindowListener(this);
ff.addWindowListener(this);
//ff.validate();
}
public void init()
{
this.add(but1);
this.add(tf1);
this.add(lb1);
this.add(tf2);
this.add(lb3);
this.add(but2);
this.add(lb4);
but1.addActionListener(this);
but2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
//TextField tf=(TextField)(e.getSource());
if( e.getSource()==but1){
a=Math.random();
//System.out.println(a);
double b =a*100;
int c=(int)b;
cc=c;
d=String.valueOf(cc);
tf1.setText(d);
}
if (e.getSource().equals(but2))
{
s=null;
s=tf2.getText();
String q=s;
if(s.length()==0){
s=qq;
System.out.println("現(xiàn)在你的值是"+qq+"不要輸入空值!");
}
tf2.setText("");
w=Integer.parseInt(s);
qq=s;
if (cc>w)
{
lb4.setText("笨蛋,猜小了你");
}
if (cc
lb4.setText("猜大了,笨的跟豬一樣,!!嘎嘎");
}
if(cc==w)
{
if(q==null)
lb4.setText("The textfield is empty!");
lb4.setText("還好,你猜對(duì)了,要不要接著挨罵了!");
}
}
}
public void windowOpened(WindowEvent e)
{
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowClosed(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowActivated(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{
}
public static void main(String[] args)
{
bb f = new bb ();
}
}
Tags - 百度 , java , gui
文章來源:http://www.tt-shopping.com/kevinlau/read.php/117.htm