Advertisement
Guest User

XOButton

a guest
Jun 20th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package game;
  2.  
  3. import javax.swing.ImageIcon;
  4. import javax.swing.JButton;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.ActionEvent;
  7.  
  8. public class XOButton extends JButton{
  9. ImageIcon X,O;
  10. byte value = 0;
  11.  
  12. public XOButton(){
  13. X = new ImageIcon(this.getClass().getResource("X.png"));
  14. O = new ImageIcon(this.getClass().getResource("O.png"));
  15. this.addActionListener((ActionListener) this);
  16. }
  17.  
  18. public void actionPerformed(ActionEvent e){
  19. value++;
  20. value%=3;
  21. switch(value){
  22. case 0:
  23. setIcon(null);
  24. break;
  25. case 1:
  26. setIcon(X);
  27. break;
  28. case 2:
  29. setIcon(O);
  30. break;
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement