人品测试

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(){
@Override
public 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();
}
}




你可能感兴趣的:(java)