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