Advertisement
Arfizato

hak

Jan 10th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4.  
  5. public class Test extends JFrame
  6. {
  7. JLabel j1;
  8. ButtonListener1 bl1;
  9. ButtonListener2 bl2 ;
  10. int count =0;
  11. public Test()
  12. {
  13. Container C = getContentPane();
  14. C.setTitle ("exemple");
  15. JLabel j1=new JLabel("0");
  16. JButton b1 = new JButton ;
  17. JButton b2 = new JButton ;
  18. bl2 = new ButtonListener2() ;
  19. bl1 = new ButtonListener1();
  20. b1.addActionListener(bl1);
  21. b2.addActionListener(bl2);
  22. C.add(b1);
  23. C.add(b2);
  24. C.add(j1);
  25.  
  26. }
  27. private class ButtonListener1 implemets ActionListener
  28. {
  29. count = count +1 ;
  30. j1.setText (String.valueOf(count));
  31. }
  32. private class ButtonListener2 implemets ActionListener
  33. {
  34. count = count -1 ;
  35. j1.setText (String.valueOf(count));
  36. }
  37.  
  38.  
  39.  
  40. public static void main(String[] args) {
  41. new Test();
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement