Guest User

Untitled

a guest
Oct 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. package JavaCombo;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. class JavaCombo extends JFrame{
  6. private JComboBox Box;
  7. private JLabel picture;
  8. private static String[] filename = {"Smiley1.jpg","Smiley2.jpg"};
  9. private Icon[] pics = {new ImageIcon(getClass().getResource(filename[0])),new ImageIcon(getClass().getResource(filename[1]))};
  10. public JavaCombo(){
  11. super("Java Combo");
  12. setLayout(new FlowLayout());
  13. Box = new JComboBox(filename);
  14. Box.addItemListener(
  15. new ItemListener(){
  16. public void itemStateChanged(ItemEvent event){
  17. if(event.getStateChange()==ItemEvent.SELECTED)
  18. picture.setIcon(pics[Box.getSelectedIndex()]);
  19. }
  20. }
  21. );
  22. add(Box);
  23. picture = new JLabel(pics[0]);
  24. add(picture);
  25. }
  26. }
  27.  
  28. ===================================================================================================
  29.  
  30. package JavaCombo;
  31. import javax.swing.JFrame;
  32.  
  33. public class JavaComboTest {
  34. public static void main(String[] args){
  35. JavaCombo myJavaCombo = new JavaCombo();
  36. myJavaCombo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37. myJavaCombo.setSize(300,120);
  38. myJavaCombo.setVisible(true);
  39. }
  40.  
  41. }
Add Comment
Please, Sign In to add comment