|
|
@ -1,7 +1,10 @@ |
|
|
|
package solitaer; |
|
|
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
import java.awt.Image; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
import javax.swing.ImageIcon; |
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
enum Symbol { |
|
|
@ -9,20 +12,31 @@ enum Symbol { |
|
|
|
} |
|
|
|
|
|
|
|
public class Card extends JPanel { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
*/ |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private int nr; |
|
|
|
private Symbol symbol; |
|
|
|
|
|
|
|
|
|
|
|
private boolean faceUp; |
|
|
|
|
|
|
|
private Image Up; |
|
|
|
private Image back; |
|
|
|
|
|
|
|
public Card(int nr, Symbol symbol, boolean faceUp) { |
|
|
|
this.setSize(72,96); |
|
|
|
this.nr = nr; |
|
|
|
this.symbol = symbol; |
|
|
|
this.faceUp = faceUp; |
|
|
|
|
|
|
|
String cardName = "" + getFileNr() + getFileSymbole(); |
|
|
|
ImageIcon iiup = new ImageIcon(getClass().getResource("images/" + cardName + ".png")); |
|
|
|
Up = iiup.getImage(); |
|
|
|
|
|
|
|
ImageIcon iiback = new ImageIcon(getClass().getResource("images/back.png")); |
|
|
|
back = iiback.getImage(); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isFaceUp() { |
|
|
@ -37,10 +51,41 @@ public class Card extends JPanel { |
|
|
|
return nr; |
|
|
|
} |
|
|
|
|
|
|
|
private String getFileNr() { |
|
|
|
if (this.nr < 10) { |
|
|
|
return "0" + this.nr; |
|
|
|
} else { |
|
|
|
return "" + this.nr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Symbol getSymbol() { |
|
|
|
return symbol; |
|
|
|
} |
|
|
|
|
|
|
|
private String getFileSymbole() { |
|
|
|
switch (this.symbol) { |
|
|
|
case Herz: |
|
|
|
return "Herz"; |
|
|
|
case Karo: |
|
|
|
return "Karo"; |
|
|
|
case Pik: |
|
|
|
return "Pik"; |
|
|
|
case Kreuz: |
|
|
|
return "Kreuz"; |
|
|
|
default: |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Image getImage() { |
|
|
|
if (faceUp) { |
|
|
|
return Up; |
|
|
|
} else { |
|
|
|
return back; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; |
|
|
@ -63,6 +108,11 @@ public class Card extends JPanel { |
|
|
|
return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
super.paintComponent(g); |
|
|
|
g.drawImage(getImage(), 0, 0, this.getWidth(), this.getHeight(), this); |
|
|
|
} |
|
|
|
|
|
|
|
} |