Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void updateReviewers() {
- jComboBox_reviewer.addMouseListener(new MouseListener() {
- @Override
- public void mouseClicked(MouseEvent e) {
- System.out.println("clicked");
- }
- @Override
- public void mousePressed(MouseEvent e) {
- System.out.println("pressed");
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- System.out.println("released");
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- System.out.println("entered");
- }
- @Override
- public void mouseExited(MouseEvent e) {
- System.out.println("exited");
- }
- }
- );
- }
- jcomboBox.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- JComboBox comboBox = (JComboBox) event.getSource();
- Object o = comboBox.getSelectedItem();
- //Any extra code
- }
- });
- package JComboBox;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- /*<applet code="JComboBoxDemo" width=200 height=120></applet>
- */
- public class JComboBoxDemo extends JApplet
- {
- JLabel jlab;
- ImageIcon hourglass, digital, analog, stopwatch;
- JComboBox <String> jcb;
- String timepieces[] = {"Digital", "Analog", "Hourglass", "Stopwatch"};
- String s;
- public void init()
- {
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- makeGUI();
- }
- });
- }
- catch(Exception exc)
- {
- System.out.println("Program can't run because of "+exc);
- }
- }
- private void makeGUI()
- {
- setLayout(new FlowLayout());
- jcb = new JComboBox<String>(timepieces);
- add(jcb);
- jcb.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- s = (String) jcb.getSelectedItem();
- jlab.setIcon(new ImageIcon(s + ".jpg"));
- }
- });
- jlab = new JLabel(new ImageIcon());
- add(jlab);
- }
- }
Add Comment
Please, Sign In to add comment