|
|
@ -2,10 +2,8 @@ package solitaer; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Graphics; |
|
|
|
import java.awt.Image; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
import javax.swing.ImageIcon; |
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
enum Symbol { |
|
|
@ -19,9 +17,6 @@ public class Card extends JPanel { |
|
|
|
private Symbol symbol; |
|
|
|
|
|
|
|
private boolean faceUp; |
|
|
|
|
|
|
|
private Image Up; |
|
|
|
private Image back; |
|
|
|
|
|
|
|
private final int IMAGE_WIDTH = 72; |
|
|
|
private final int IMAGE_HIGHT = 96; |
|
|
@ -31,13 +26,6 @@ public class Card extends JPanel { |
|
|
|
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() { |
|
|
@ -52,7 +40,7 @@ public class Card extends JPanel { |
|
|
|
return nr; |
|
|
|
} |
|
|
|
|
|
|
|
private String getFileNr() { |
|
|
|
private String getNrText() { |
|
|
|
if (this.nr < 10) { |
|
|
|
return "0" + this.nr; |
|
|
|
} else { |
|
|
@ -64,7 +52,7 @@ public class Card extends JPanel { |
|
|
|
return symbol; |
|
|
|
} |
|
|
|
|
|
|
|
private String getFileSymbole() { |
|
|
|
private String getSymboleText() { |
|
|
|
switch (this.symbol) { |
|
|
|
case Herz: |
|
|
|
return "Herz"; |
|
|
@ -79,14 +67,6 @@ public class Card extends JPanel { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Image getImage() { |
|
|
|
if (faceUp) { |
|
|
|
return Up; |
|
|
|
} else { |
|
|
|
return back; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; |
|
|
@ -113,9 +93,33 @@ public class Card extends JPanel { |
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
super.paintComponent(g); |
|
|
|
g.drawImage(getImage(), 0, 0, this.getWidth(), this.getHeight(), this); |
|
|
|
g.setColor(Color.black); |
|
|
|
g.drawRect(0, 0, this.getWidth()-1, this.getHeight()-1); |
|
|
|
paintCard(g); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void paintCard(Graphics g) { |
|
|
|
if (faceUp) { |
|
|
|
g.setColor(Color.white); |
|
|
|
g.fillRect(0, 0, this.getWidth(), this.getHeight()); |
|
|
|
|
|
|
|
g.setColor(Color.black); |
|
|
|
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); |
|
|
|
|
|
|
|
if (this.symbol == Symbol.Herz || this.symbol == Symbol.Karo) |
|
|
|
g.setColor(Color.red); |
|
|
|
else |
|
|
|
g.setColor(Color.black); |
|
|
|
|
|
|
|
String text = "" + this.getNrText() + " " + this.getSymboleText(); |
|
|
|
g.drawString(text, 3, 15); |
|
|
|
} else { |
|
|
|
g.setColor(Color.blue); |
|
|
|
g.fillRect(0, 0, this.getWidth(), this.getHeight()); |
|
|
|
|
|
|
|
g.setColor(Color.black); |
|
|
|
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |