import java.awt.Color;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Random;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;public class RP extends JFrame{public RP(){JPanel basp=new JPanel();//画布basp.setColor.BLUE); //背景GridLayout gl=new GridLayout(2,1);basp.setLayout(gl);JPanel above=new JPanel();above.setColor.GREEN);< /p>JLabel jl=new JLabel("请输入姓名:");final JLabel bjl=new JLabel();JTextField jtx=new JTextField(15);JButton commi=new JButton("确定...");commi.addActionListener(new ActionListener(){@Overridepublic void actionPerformed(ActionEvent e) {Random ran=new Random();bjl.setText("");int i=ran.nextInt(4);switch(i){case 0:bjl.setText("哎我,这人品,您怎么忍心出来呢!");break;case 1:bjl.setText("天哪,就您这人品,没少做坏事吧!");break;case 2:bjl.setText("哎呦,个人魅力不错哦!");break;case 3:bjl.setText("哇哦,能给我签个名吗?!");break;}}});above.add(jl);above.add(jtx);above.add(commi);JPanel bottom=new JPanel();bottom.setColor.YELLOW);< /p>bottom.add(bjl);basp.add(above);basp.add(bottom);setContentPane(basp);//jframe加载画布setBounds(200,200,400,300);//jframe显示位置setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗体关闭方式setTitle(" 人品测试,等你加入");//标题setVisible(true);//可见性}public static void main(String[] args) {new RP();}}