Guest User

Untitled

a guest
Jun 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4.  
  5.  
  6. //Klassen kort, Subklass till JButton
  7. public class Kort extends JButton{
  8.  
  9.  
  10. //Klassvariabler
  11.  
  12. private Status status;
  13. private Icon ikon;
  14.  
  15. //Tillstånd de olika korten kan befinna sig i
  16.  
  17. public enum Status {DOLT, SYNLIGT, SAKNAS};
  18.  
  19. //Kontruktorer
  20.  
  21. public Kort(Icon ikon) {
  22. this(ikon, Status.SAKNAS);
  23. }
  24.  
  25. public Kort(Icon ikon, Status status) {
  26. this.ikon = ikon;
  27. this.setStatus(status);
  28. }
  29.  
  30.  
  31.  
  32. //Ge kortet nytt tillstånd
  33.  
  34. public void setStatus(Status status){
  35. this.status = status;
  36. if (getStatus() == Status.DOLT){
  37. this.setBackground(Color.blue);
  38. this.setIcon(null);
  39. ////// KAP6 sid 200
  40. }
  41. else if (getStatus() == Status.SAKNAS){
  42. this.setIcon(null);
  43. this.setBackground(Color.white);
  44. }
  45. else if(getStatus() == Status.SYNLIGT){
  46. this.setIcon(this.ikon);
  47. }
  48. }
  49.  
  50. //Returnera kortets tillstånd
  51.  
  52. public Status getStatus(){
  53. return(this.status);
  54. }
  55.  
  56. //Kopiera ett kort
  57.  
  58. public Kort copy(){
  59. Kort kort = new Kort(this.ikon, this.status);
  60. return (kort);
  61. }
  62.  
  63. //Jämför 2 kort
  64.  
  65. public boolean equals(Kort kort){
  66. if(kort.getIcon() == this.getIcon()){
  67. return(true);
  68. }
  69. else{
  70. return(false);
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment