Browse Source

Fix Card and StartStack DRAW

feature_solitaer_StartStack
Alexander Hartung 3 years ago
parent
commit
7d0878431e
  1. 54
      src/main/java/solitaer/Card.java
  2. 12
      src/main/java/solitaer/StartStack.java

54
src/main/java/solitaer/Card.java

@ -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);
}
}
}

12
src/main/java/solitaer/StartStack.java

@ -1,16 +1,14 @@
package solitaer;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class StartStack extends JPanel {
private static final long serialVersionUID = 1L;
private Image im;
private ArrayList<Card> stack = new ArrayList<Card>();
private final int OFFSET_VALUE = 20;
@ -71,9 +69,11 @@ public class StartStack extends JPanel {
// TODO Auto-generated method stub
super.paintComponent(g);
if (stack.size() == 0) {
ImageIcon ii = new ImageIcon(getClass().getResource("images/empty.png"));
im = ii.getImage();
g.drawImage(im, 0, 0, this.getWidth(), 96, this);
g.setColor(Color.gray);
g.fillRect(0, 0, this.getWidth(), 96);
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth()-1, 96-1);
}
}

Loading…
Cancel
Save