import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class B3 {
public static void main(String[] args) {
JFrame jf = new JFrame();
JPanel jp = new JPanel();
jp.setLayout(null);
final JTextArea jta = new JTextArea();
jta.setRows(2);
jta.setMargin(new Insets(0, 80, 0, 20));
jta.setBounds(0,0,222,70);
JButton jb1 = new JButton("输入");
jb1.setBounds(30,120,70,50);
JButton jb2 = new JButton("取消");
jb2.setBounds(130,120,70,50);
jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
int num = getNum();
if(num>50){
jta.setText(""+num);
}else{
jta.setText("数字小于50");
}
}
});
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
jta.setText("");
}
});
jp.add(jta);
jp.add(jb1);
jp.add(jb2);
jf.add(jp);
jf.setSize(222,222);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static int getNum(){
int a = (int)(Math.random()*100);
return a;
}
}