Home > Java > javaTutorial > Implementation method of swing drop-down menu in java

Implementation method of swing drop-down menu in java

高洛峰
Release: 2017-01-17 11:19:55
Original
2262 people have browsed it

The example of this article describes the implementation method of swing drop-down menu in java. Share it with everyone for your reference. The details are as follows:

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"));
  }
}
Copy after login

I hope this article will be helpful to everyone’s java programming.

For more articles related to Java's swing drop-down menu implementation method, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template