Java Implementation of the game set.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

8 years ago
8 years ago
8 years ago
  1. package net.jrtechs.setgame;
  2. import java.awt.Color;
  3. import javax.swing.JButton;
  4. public class SetButton extends JButton
  5. {
  6. private boolean pressed;
  7. private Card card;
  8. private int loc;
  9. SetButton()
  10. {
  11. pressed = false;
  12. }
  13. SetButton(int x)
  14. {
  15. pressed = false;
  16. loc = x;
  17. }
  18. public void clicked()
  19. {
  20. if(pressed)
  21. {
  22. pressed = false;
  23. this.setBackground(Color.WHITE);
  24. }
  25. else
  26. {
  27. this.setBackground(Color.gray);
  28. pressed = true;
  29. }
  30. }
  31. public void update()
  32. {
  33. if(card != null)
  34. {
  35. //sets the image of the button baised on its properties
  36. //images located in the /src folder, file are named as a 4 digit number
  37. //each digit represents a property of the image(shape, number, color, shading)
  38. String src = "/net/jrtechs/setgame/img/" + card.getShape() + card.getNumber() + card.getColor() + card.getShading() + ".png";
  39. //this.setText(card.toString());
  40. this.setIcon(new javax.swing.ImageIcon(getClass().getResource(src)));
  41. }
  42. }
  43. public Card getCard()
  44. {
  45. return card;
  46. }
  47. public void setCard(Card newCard)
  48. {
  49. card = newCard;
  50. }
  51. public int getLoc()
  52. {
  53. return loc;
  54. }
  55. public boolean getPressed()
  56. {
  57. return pressed;
  58. }
  59. public void setPressed(boolean sel)
  60. {
  61. pressed = sel;
  62. }
  63. }