Advertisement
rohitmehra

Untitled

Dec 17th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. // Demonstrate JComboBox.
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. /*
  6. <applet code="JComboBoxDemo" width=300 height=100>
  7. </applet>
  8. */
  9. public class JComboBoxDemo extends JApplet {
  10. JLabel jlab;
  11. ImageIcon france, germany, italy, japan;
  12. JComboBox jcb;
  13. String flags[] = { "France", "Germany", "Italy", "Japan" };
  14. public void init() {
  15. try {
  16. SwingUtilities.invokeAndWait(
  17. new Runnable() {
  18. public void run() {
  19. makeGUI();
  20. }
  21. }
  22. );
  23. } catch (Exception exc) {
  24. System.out.println("Can't create because of " + exc);
  25. }
  26. }
  27. private void makeGUI() {
  28. // Change to flow layout.
  29. setLayout(new FlowLayout());
  30. // Instantiate a combo box and add it to the content pane.
  31. jcb = new JComboBox(flags);
  32. add(jcb);
  33. // Handle selections.
  34. jcb.addActionListener(new ActionListener() {
  35. public void actionPerformed(ActionEvent ae) {
  36. String s = (String) jcb.getSelectedItem();
  37. jlab.setIcon(new ImageIcon(s + ".gif"));
  38. }
  39. });
  40. // Create a label and add it to the content pane.
  41. jlab = new JLabel(new ImageIcon("france.gif"));
  42. add(jlab);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement