本文实例讲述了java之swing下拉菜单实现方法。分享给大家供大家参考。具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class test extends JApplet
implements ItemListener{
JLabel jtf;
ImageIcon a1, a2, a3;
public void init(){
Container contentPane = getContentPane();
contentPane.setLayout( new FlowLayout());
JComboBox jc = new JComboBox();
jc.addItem( "6" );
jc.addItem( "7" );
jc.addItem( "8" );
jc.addItemListener( this );
contentPane.add(jc);
jtf = new JLabel( new ImageIcon( "D:/data/Images/6.gif" ));
contentPane.add(jtf);
}
public void itemStateChanged(ItemEvent ie){
String s = (String)ie.getItem();
jtf.setIcon( new ImageIcon( "D:/data/Images/" +s+ ".gif" ));
}
}
|
希望本文所述对大家的java程序设计有所帮助。