JAVA选项事件

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class WindowE extends JFrame{
	Container content;
	JComboBox combo;
	JLabel j1;
	public WindowE(){
	 content=getContentPane();
	 String s[]={"C#","C++","PHP","JAVA"};
	 combo=new JComboBox(s);
	 j1=new JLabel();
	 content.setLayout(new FlowLayout());
	 combo.addItemListener(new Mo());
	 content.add(combo);
	 content.add(j1);
	 setTitle("选项事件测试");
    setSize(200,300);
    setVisible(true);
	}
	class Mo implements ItemListener{
		public void itemStateChanged(ItemEvent e){
			//if(combo.getSelectedIndex()==0)
				 j1.setIcon(new ImageIcon("1.jpg"));
			//if(combo.getSelectedIndex()==1)
				 j1.setIcon(new ImageIcon("2.jpg"));
			//if(combo.getSelectedIndex()==2)
				j1.setIcon(new ImageIcon("3.jpg"));
			//if(combo.getSelectedIndex()==3)
				j1.setIcon(new ImageIcon("4.jpg"));
			
		}
	}
	

	
	public static void main(String[] args) {
		new WindowE();

	}

}

 

posted @ 2012-04-27 19:35  残阳飞雪  阅读(474)  评论(0编辑  收藏  举报