十二、SWING界面设计
一、代码
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class introduce extends JFrame
{
	public introduce()
	{
		JFrame a=new JFrame();
		a.setLayout(new FlowLayout());
		a.setTitle("Introduction");
		a.setSize(400,100);
		a.setLocation(300,240);
		String proList[] = { "姓名","性别","年龄","民族" ,"籍贯","学号","学院","专业"};
		JComboBox comboBox;
		Container conPane = getContentPane();   
	    comboBox = new JComboBox(proList);    
	    comboBox.setEditable(true);     
	    conPane.add(comboBox); 
	    JTextField b=new JTextField(20);
	    a.add(conPane);
	    a.add(b);
	    comboBox.addActionListener(new ActionListener()
	    		{public void actionPerformed(ActionEvent e) 
	    		{  if(comboBox.getSelectedItem().equals("姓名"))
	    			b.setText("赵燕");
	    		else if(comboBox.getSelectedItem().equals("性别"))
	    			b.setText("女");
	    		else 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("20173311138");
	    		else if(comboBox.getSelectedItem().equals("学院"))
	    			b.setText("计算机学院");
	    		else if(comboBox.getSelectedItem().equals("专业"))
	    			b.setText("网络工程");
	    		}
	    		    });
	    a.setVisible(true);
	}
	    }
public class Introduction {
	public static void main(String[] args)
	{
			new introduce();
			}
}
二、运行结果









三、心得体会
在编写程序时,包的插入出现问题,导致运行错误,总是显示未插入包。在设计界面过于简单,未能实现更多功能。
 
                    
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号