编写java程序。实现功能:随机输入一个数字 假如数字大于50 显示在屏幕中央文本框里

来源:百度知道 编辑:UC知道 时间:2024/07/16 13:42:48
随机输入一个数字 假如数字大于50 显示在屏幕中央文本框里 有2个按钮 输入 取消

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.s