import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class RamdomNum_3_20
{
private Frame fr;
private Button but1,but2,but3;
private Button but4;
private Label la1,la2,la3;
private TextField tf1,tf2,tf3;
RamdomNum_3_20()
{
init();
}
public void init()
{
fr = new Frame("RamdomNum");
but1 = new Button("Generate");
but2 = new Button("Generate");
but3 = new Button("Generate");
la1 = new Label("0--->1");
la2 = new Label("1-->10");
la3 = new Label("1---6");
fr.setBounds(300,100,300,150);
fr.setLayout(new FlowLayout());
tf1 = new TextField(15);
tf2 = new TextField(15);
tf3 = new TextField(15);
fr.add(la1);
fr.add(tf1);
fr.add(but1);
fr.add(la2);
fr.add(tf2);
fr.add(but2);
fr.add(la3);
fr.add(tf3);
fr.add(but3);
myEvent();
fr.setVisible(true);
}
private void myEvent()
{
fr.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
but2.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
Integer num = new Integer(((int)(Math.random()*10) + 1));
String str = num.toString();
tf2.setText(str);
}
});
but1.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
int num = ((int)(Math.random()*10) + 1);
if(num<=5)
num = 0;
else
num = 1;
Integer num0 = new Integer(num);
String str = num0.toString();
tf1.setText(str);
}
});
but3.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
Integer num = new Integer(((int)(Math.random()*10) + 1));
while(num<= 6)
{
String str = num.toString();
tf3.setText(str);
break;//这里必须break退出,不然就一直在里面了
}
}
});
}
public static void main(String[] args)
{
new RamdomNum_3_20();
}
}