实验十二

一、源代码

package ziwojieshao;
import java.awt.FlowLayout;
import javax.swing.*;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AA extends JFrame{
public AA()
{
JFrame jf1=new JFrame ("Hellow");
jf1.setLayout(new FlowLayout());
jf1.getContentPane().add(new JButton("姓名")) ;
jf1.getContentPane().add(new JTextField("白云超",08)) ;

JRadioButton j1=new JRadioButton("男",true);
JRadioButton j2=new JRadioButton("女");
ButtonGroup g=new ButtonGroup();
g.add(j1);
g.add(j2);
JPanel p1=new JPanel();
p1.add(j1);
p1.add(j2);
jf1.getContentPane().add(p1);
jf1.setSize(320,210);

String proList[] = { "年龄","民族" ,"籍贯","学号","学院","专业"};
JComboBox comboBox;
Container conPane = getContentPane(); 
comboBox = new JComboBox(proList); 
comboBox.setEditable(true); 
conPane.add(comboBox);
JTextField b=new JTextField(20);
jf1.add(conPane);
jf1.add(b);
comboBox.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)

if(comboBox.getSelectedItem().equals("年龄"))
b.setText("20");
else if(comboBox.getSelectedItem().equals("民族"))
b.setText("回");
else if(comboBox.getSelectedItem().equals("籍贯"))
b.setText("青海 大通");
else if(comboBox.getSelectedItem().equals("学号"))
b.setText("20173311108");
else if(comboBox.getSelectedItem().equals("学院"))
b.setText("计算机学院");
else if(comboBox.getSelectedItem().equals("专业"))
b.setText("网络工程");
}
});


jf1.setVisible(true);
}
public static void main (String[] args) {
new AA()
}

二.实验心得

实验看似简单,但是操作起来还是有一定的难度,编程时要细心、多练。

 
 
 
好文要顶  关注我  收藏该文   

你可能感兴趣的:(实验十二)