Guest User

Untitled

a guest
Mar 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. private void updateReviewers() {
  2. jComboBox_reviewer.addMouseListener(new MouseListener() {
  3.  
  4. @Override
  5. public void mouseClicked(MouseEvent e) {
  6. System.out.println("clicked");
  7. }
  8.  
  9. @Override
  10. public void mousePressed(MouseEvent e) {
  11. System.out.println("pressed");
  12. }
  13.  
  14. @Override
  15. public void mouseReleased(MouseEvent e) {
  16. System.out.println("released");
  17. }
  18.  
  19. @Override
  20. public void mouseEntered(MouseEvent e) {
  21. System.out.println("entered");
  22. }
  23.  
  24. @Override
  25. public void mouseExited(MouseEvent e) {
  26. System.out.println("exited");
  27. }
  28.  
  29. }
  30. );
  31.  
  32. }
  33.  
  34. jcomboBox.addActionListener(new ActionListener() {
  35.  
  36. public void actionPerformed(ActionEvent e)
  37. {
  38. JComboBox comboBox = (JComboBox) event.getSource();
  39. Object o = comboBox.getSelectedItem();
  40. //Any extra code
  41. }
  42. });
  43.  
  44. package JComboBox;
  45.  
  46. import java.awt.*;
  47.  
  48. import java.awt.event.*;
  49.  
  50. import javax.swing.*;
  51.  
  52. /*<applet code="JComboBoxDemo" width=200 height=120></applet>
  53. */
  54.  
  55. public class JComboBoxDemo extends JApplet
  56. {
  57.  
  58. JLabel jlab;
  59. ImageIcon hourglass, digital, analog, stopwatch;
  60. JComboBox <String> jcb;
  61. String timepieces[] = {"Digital", "Analog", "Hourglass", "Stopwatch"};
  62. String s;
  63.  
  64. public void init()
  65. {
  66. try {
  67. SwingUtilities.invokeAndWait(new Runnable() {
  68.  
  69. public void run() {
  70.  
  71. makeGUI();
  72. }
  73. });
  74. }
  75.  
  76. catch(Exception exc)
  77. {
  78. System.out.println("Program can't run because of "+exc);
  79. }
  80. }
  81.  
  82. private void makeGUI()
  83. {
  84. setLayout(new FlowLayout());
  85. jcb = new JComboBox<String>(timepieces);
  86. add(jcb);
  87.  
  88. jcb.addActionListener(new ActionListener() {
  89.  
  90. public void actionPerformed(ActionEvent ae) {
  91.  
  92. s = (String) jcb.getSelectedItem();
  93. jlab.setIcon(new ImageIcon(s + ".jpg"));
  94. }
  95. });
  96.  
  97. jlab = new JLabel(new ImageIcon());
  98. add(jlab);
  99. }
  100. }
Add Comment
Please, Sign In to add comment