From 7caebafde98f0a0534788cce725aadf29f99395a Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Wed, 26 Jan 2022 23:43:32 +0100 Subject: [PATCH 1/5] Add MouseListener --- src/main/java/solitaer/MyMouseListener.java | 60 +++++++++++++++++++ src/main/java/solitaer/SolitaerGamePanel.java | 19 ++++-- 2 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/main/java/solitaer/MyMouseListener.java diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java new file mode 100644 index 0000000..a5db8af --- /dev/null +++ b/src/main/java/solitaer/MyMouseListener.java @@ -0,0 +1,60 @@ +package solitaer; + +import java.awt.Component; +import java.awt.event.MouseEvent; + +import javax.swing.SwingUtilities; +import javax.swing.event.MouseInputListener; + +public class MyMouseListener implements MouseInputListener { + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + System.out.println("DOWN"); + Component com = SwingUtilities.getDeepestComponentAt( + e.getComponent(), e.getX(), e.getY()); + System.out.println("########"); + System.out.println(com.toString()); + System.out.println(com.getParent().toString()); + System.out.println("########"); + + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseDragged(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseMoved(MouseEvent e) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 3577a3a..bfe5a90 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -7,17 +7,26 @@ import javax.swing.JPanel; public class SolitaerGamePanel extends JPanel { - /** - * - */ private static final long serialVersionUID = 1L; + private CardDeck deck; + private MyMouseListener mouseL; public SolitaerGamePanel() { setLayout(null); + + mouseL = new MyMouseListener(); + this.addMouseListener(mouseL); + + + deck = new CardDeck(); + + + StartStack a = new StartStack(25,25); - a.addCard(new Card(13, Symbol.Karo, true)); - a.addCard(new Card(1, Symbol.Karo, true)); + a.addCard(deck.getDeck().get(0)); + deck.getDeck().get(1).setFaceUp(true); + a.addCard((deck.getDeck().get(1))); this.add(a); StartStack b = new StartStack(200,25); From 421cd8903f8d74d48dbad28bd7e969f4382f7a1f Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Thu, 27 Jan 2022 21:28:46 +0100 Subject: [PATCH 2/5] Add BaseStack Refactor StartStack --- src/main/java/solitaer/BaseStack.java | 49 +++++++++++++++++++++ src/main/java/solitaer/MyMouseListener.java | 20 +++++++-- src/main/java/solitaer/StartStack.java | 29 +++--------- 3 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 src/main/java/solitaer/BaseStack.java diff --git a/src/main/java/solitaer/BaseStack.java b/src/main/java/solitaer/BaseStack.java new file mode 100644 index 0000000..7300cb9 --- /dev/null +++ b/src/main/java/solitaer/BaseStack.java @@ -0,0 +1,49 @@ +package solitaer; + +import java.util.ArrayList; + +import javax.swing.JPanel; + +public abstract class BaseStack extends JPanel { + private static final long serialVersionUID = 1L; + private ArrayList stack = new ArrayList(); + private final int OFFSET_VALUE = 20; + int offset; + + public BaseStack() { + // TODO Auto-generated constructor stub + offset = 0; + } + + public boolean stackIsEmpty() { + return stack.isEmpty(); + } + + public void addCard(Card _card) { + _card.setLocation(0, offset); + stack.add(_card); + RenderStackNew(); + offset += OFFSET_VALUE; + } + + private void RenderStackNew() { + this.removeAll(); + // Alles neu Zeichnen + for (int i = stack.size() - 1; i >= 0; i--) { + this.add(stack.get(i)); + } + this.repaint(); + } + + public Card removeLastCard() { + if (stack.size() != 0) { + Card LastCard = stack.remove(stack.size() - 1); + RenderStackNew(); + return LastCard; + } + return null; + + } + + protected abstract boolean cardCheck(Card _topStack, Card _playerCard); +} diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index a5db8af..7a29a4b 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -20,10 +20,22 @@ public class MyMouseListener implements MouseInputListener { System.out.println("DOWN"); Component com = SwingUtilities.getDeepestComponentAt( e.getComponent(), e.getX(), e.getY()); - System.out.println("########"); - System.out.println(com.toString()); - System.out.println(com.getParent().toString()); - System.out.println("########"); +// System.out.println("########"); +// System.out.println(com.toString()); +// System.out.println(com.getParent().toString()); +// System.out.println("########"); + + //Leeres StartFeld + if (com instanceof StartStack) { + System.out.println("Leer Start"); + + } + //Karte, die in einem StartStack liegt + else if(com instanceof Card && com.getParent() instanceof StartStack) { + System.out.println("Karte in StartStack"+com.toString()); + + ((BaseStack)com.getParent()).removeLastCard(); + } } diff --git a/src/main/java/solitaer/StartStack.java b/src/main/java/solitaer/StartStack.java index 7bc782e..28710e4 100644 --- a/src/main/java/solitaer/StartStack.java +++ b/src/main/java/solitaer/StartStack.java @@ -2,28 +2,22 @@ package solitaer; import java.awt.Color; import java.awt.Graphics; -import java.util.ArrayList; -import javax.swing.JPanel; -public class StartStack extends JPanel { +public class StartStack extends BaseStack { private static final long serialVersionUID = 1L; - private ArrayList stack = new ArrayList(); - private final int OFFSET_VALUE = 20; private final int IMAGE_WIDTH = 72; private final int IMAGE_HIGHT = 450; - private int offset; public StartStack(int _x, int _y) { + super(); super.setLocation(_x, _y); super.setSize(IMAGE_WIDTH, IMAGE_HIGHT); super.setOpaque(false); super.setLayout(null); - - offset = 0; } public boolean cardCheck(Card _topStack, Card _playerCard) { @@ -49,26 +43,13 @@ public class StartStack extends JPanel { } } - public void addCard(Card _card) { - _card.setLocation(0, offset); - stack.add(_card); - addtoPanel(); - offset += OFFSET_VALUE; - } - - private void addtoPanel() { - this.removeAll(); - //Alles neu Zeichnen - for (int i = stack.size() - 1; i >= 0; i--) { - this.add(stack.get(i)); - } - } + @Override protected void paintComponent(Graphics g) { // TODO Auto-generated method stub super.paintComponent(g); - if (stack.size() == 0) { + if (stackIsEmpty()) { g.setColor(Color.gray); g.fillRect(0, 0, this.getWidth(), 96); @@ -77,4 +58,6 @@ public class StartStack extends JPanel { } } + + } From b11a6244b7c46f61a67639808486d63ef9eb07d2 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Thu, 27 Jan 2022 22:00:44 +0100 Subject: [PATCH 3/5] Turn Card with Mouse --- src/main/java/solitaer/BaseStack.java | 9 +++++ src/main/java/solitaer/Card.java | 3 +- src/main/java/solitaer/MyMouseListener.java | 31 ++++++++++++++- src/main/java/solitaer/SaveStack.java | 38 +++++++++++++++++++ src/main/java/solitaer/SolitaerGamePanel.java | 12 +++++- 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 src/main/java/solitaer/SaveStack.java diff --git a/src/main/java/solitaer/BaseStack.java b/src/main/java/solitaer/BaseStack.java index 7300cb9..aabbc6f 100644 --- a/src/main/java/solitaer/BaseStack.java +++ b/src/main/java/solitaer/BaseStack.java @@ -18,6 +18,15 @@ public abstract class BaseStack extends JPanel { public boolean stackIsEmpty() { return stack.isEmpty(); } + + public Card peekLastCard() { + if(!stackIsEmpty()) { + return stack.get(stack.size()-1); + } else { + return null; + } + + } public void addCard(Card _card) { _card.setLocation(0, offset); diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 1933d7a..af55cfc 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -69,7 +69,8 @@ public class Card extends JPanel { @Override public String toString() { - return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; + //return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; + return "Card NR="+nr+" | Symbole="+symbol+" | Face="+faceUp; } @Override diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 7a29a4b..140c2a9 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -7,6 +7,15 @@ import javax.swing.SwingUtilities; import javax.swing.event.MouseInputListener; public class MyMouseListener implements MouseInputListener { + + private SaveStack save; + private BaseStack tempStack; + private Card tempCard; + + public MyMouseListener(SaveStack _save) { + // TODO Auto-generated constructor stub + this.save = _save; + } @Override public void mouseClicked(MouseEvent e) { @@ -32,9 +41,27 @@ public class MyMouseListener implements MouseInputListener { } //Karte, die in einem StartStack liegt else if(com instanceof Card && com.getParent() instanceof StartStack) { - System.out.println("Karte in StartStack"+com.toString()); + tempCard = (Card) com; + tempStack = (StartStack) com.getParent(); + + //Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um + if(!tempCard.isFaceUp()) { + if(tempStack.peekLastCard().equals(tempCard)) { + tempCard.setFaceUp(true); + tempCard.repaint(); + System.out.println("Turn"+tempCard.toString()); + } + + + } + + + //System.out.println("Karte in StartStack"+com.toString()); + + + - ((BaseStack)com.getParent()).removeLastCard(); + //save.addCard(((BaseStack)com.getParent()).removeLastCard());; } } diff --git a/src/main/java/solitaer/SaveStack.java b/src/main/java/solitaer/SaveStack.java new file mode 100644 index 0000000..d95974f --- /dev/null +++ b/src/main/java/solitaer/SaveStack.java @@ -0,0 +1,38 @@ +package solitaer; + +import java.awt.Color; +import java.awt.Graphics; + +public class SaveStack extends BaseStack { + + private static final long serialVersionUID = 1L; + + public SaveStack(int _x, int _y) { + // TODO Auto-generated constructor stub + super(); + super.setLocation(_x, _y); + super.setSize(72, 450); + super.setOpaque(false); + super.setLayout(null); + } + + @Override + protected boolean cardCheck(Card _topStack, Card _playerCard) { + // TODO Auto-generated method stub + return false; + } + + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + if (stackIsEmpty()) { + g.setColor(Color.pink); + g.fillRect(0, 0, this.getWidth(), 96); + + g.setColor(Color.black); + g.drawRect(0, 0, this.getWidth() - 1, 96 - 1); + } + } + +} diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index bfe5a90..14ab7cf 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -10,12 +10,14 @@ public class SolitaerGamePanel extends JPanel { private static final long serialVersionUID = 1L; private CardDeck deck; private MyMouseListener mouseL; + + private SaveStack save =new SaveStack(500,250); public SolitaerGamePanel() { setLayout(null); - mouseL = new MyMouseListener(); + mouseL = new MyMouseListener(save); this.addMouseListener(mouseL); @@ -25,12 +27,18 @@ public class SolitaerGamePanel extends JPanel { StartStack a = new StartStack(25,25); a.addCard(deck.getDeck().get(0)); - deck.getDeck().get(1).setFaceUp(true); + deck.getDeck().get(1).setFaceUp(false); a.addCard((deck.getDeck().get(1))); this.add(a); StartStack b = new StartStack(200,25); this.add(b); + + //save = new SaveStack(500,250); + this.add(save); + + + } From cc51b3fa681756768b2a561b4642d8b6fed0d167 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Thu, 27 Jan 2022 22:36:28 +0100 Subject: [PATCH 4/5] Move Cards between StartStack with Mouse --- src/main/java/solitaer/BaseStack.java | 31 +++++--- src/main/java/solitaer/MyMouseListener.java | 73 +++++++++++-------- src/main/java/solitaer/SolitaerGamePanel.java | 26 ++++++- 3 files changed, 89 insertions(+), 41 deletions(-) diff --git a/src/main/java/solitaer/BaseStack.java b/src/main/java/solitaer/BaseStack.java index aabbc6f..e8064d0 100644 --- a/src/main/java/solitaer/BaseStack.java +++ b/src/main/java/solitaer/BaseStack.java @@ -1,5 +1,7 @@ package solitaer; +import java.lang.invoke.TypeDescriptor.OfField; +import java.time.OffsetDateTime; import java.util.ArrayList; import javax.swing.JPanel; @@ -25,7 +27,14 @@ public abstract class BaseStack extends JPanel { } else { return null; } - + } + + public int indexOfCard(Card _card) { + return stack.indexOf(_card); + } + + public int stackSize() { + return stack.size(); } public void addCard(Card _card) { @@ -35,23 +44,23 @@ public abstract class BaseStack extends JPanel { offset += OFFSET_VALUE; } - private void RenderStackNew() { - this.removeAll(); - // Alles neu Zeichnen - for (int i = stack.size() - 1; i >= 0; i--) { - this.add(stack.get(i)); - } - this.repaint(); - } - public Card removeLastCard() { if (stack.size() != 0) { Card LastCard = stack.remove(stack.size() - 1); + offset -= OFFSET_VALUE; RenderStackNew(); return LastCard; } return null; - + } + + private void RenderStackNew() { + this.removeAll(); + // Alles neu Zeichnen + for (int i = stack.size() - 1; i >= 0; i--) { + this.add(stack.get(i)); + } + this.repaint(); } protected abstract boolean cardCheck(Card _topStack, Card _playerCard); diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 140c2a9..4ca99b8 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -7,11 +7,12 @@ import javax.swing.SwingUtilities; import javax.swing.event.MouseInputListener; public class MyMouseListener implements MouseInputListener { - + private SaveStack save; private BaseStack tempStack; + private BaseStack selectedStack; private Card tempCard; - + public MyMouseListener(SaveStack _save) { // TODO Auto-generated constructor stub this.save = _save; @@ -27,41 +28,55 @@ public class MyMouseListener implements MouseInputListener { public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub System.out.println("DOWN"); - Component com = SwingUtilities.getDeepestComponentAt( - e.getComponent(), e.getX(), e.getY()); -// System.out.println("########"); -// System.out.println(com.toString()); -// System.out.println(com.getParent().toString()); -// System.out.println("########"); - - //Leeres StartFeld + Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); + + // Leeres StartFeld if (com instanceof StartStack) { System.out.println("Leer Start"); - + } - //Karte, die in einem StartStack liegt - else if(com instanceof Card && com.getParent() instanceof StartStack) { + // Karte, die in einem StartStack liegt + else if (com instanceof Card && com.getParent() instanceof StartStack) { tempCard = (Card) com; tempStack = (StartStack) com.getParent(); - - //Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um - if(!tempCard.isFaceUp()) { - if(tempStack.peekLastCard().equals(tempCard)) { - tempCard.setFaceUp(true); - tempCard.repaint(); - System.out.println("Turn"+tempCard.toString()); + + if (save.stackIsEmpty()) { + // Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um + if (!tempCard.isFaceUp()) { + if (tempStack.peekLastCard().equals(tempCard)) { + tempCard.setFaceUp(true); + tempCard.repaint(); + } + } + // Card faceUp + else { + // move all Cards below the selected Card to Save + int index = tempStack.indexOfCard(tempCard); + while (tempStack.stackSize() - 1 >= index) { + save.addCard(tempStack.removeLastCard()); + } + selectedStack = tempStack; + + } + } + //saveStack is NOT empty + else { + if(selectedStack == null) { + System.out.println("ERROR selectedStack in StartStack"); + } + if(tempStack.cardCheck(tempStack.peekLastCard(), save.peekLastCard())) { + while(!save.stackIsEmpty()) { + tempStack.addCard(save.removeLastCard()); + } + } else { + //Alles wieder auf den Ursprünglichen Stack packen + while(!save.stackIsEmpty()) { + selectedStack.addCard(save.removeLastCard()); + } } - + selectedStack = null; } - - - //System.out.println("Karte in StartStack"+com.toString()); - - - - - //save.addCard(((BaseStack)com.getParent()).removeLastCard());; } } diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 14ab7cf..d94b99c 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -26,14 +26,38 @@ public class SolitaerGamePanel extends JPanel { StartStack a = new StartStack(25,25); + a.addCard(deck.getDeck().get(0)); - deck.getDeck().get(1).setFaceUp(false); + + deck.getDeck().get(5).setFaceUp(true); + a.addCard((deck.getDeck().get(5))); + + deck.getDeck().get(4).setFaceUp(true); + a.addCard((deck.getDeck().get(4))); + + deck.getDeck().get(3).setFaceUp(true); + a.addCard((deck.getDeck().get(3))); + + deck.getDeck().get(2).setFaceUp(true); + a.addCard((deck.getDeck().get(2))); + + deck.getDeck().get(1).setFaceUp(true); a.addCard((deck.getDeck().get(1))); + this.add(a); StartStack b = new StartStack(200,25); + + deck.getDeck().get(32).setFaceUp(true); + b.addCard((deck.getDeck().get(32))); this.add(b); + StartStack c = new StartStack(375,25); + + deck.getDeck().get(33).setFaceUp(true); + c.addCard((deck.getDeck().get(33))); + this.add(c); + //save = new SaveStack(500,250); this.add(save); From 5aab0411798e7bbd41c70e75d0a2bfc51972ce0e Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Thu, 27 Jan 2022 22:51:55 +0100 Subject: [PATCH 5/5] Refactor Start- Save- BaseStack and MyMousListener --- src/main/java/solitaer/BaseStack.java | 6 ++++-- src/main/java/solitaer/MyMouseListener.java | 18 +++++++++--------- src/main/java/solitaer/SaveStack.java | 6 +++--- src/main/java/solitaer/StartStack.java | 10 +++------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/main/java/solitaer/BaseStack.java b/src/main/java/solitaer/BaseStack.java index e8064d0..84dfab2 100644 --- a/src/main/java/solitaer/BaseStack.java +++ b/src/main/java/solitaer/BaseStack.java @@ -1,12 +1,14 @@ package solitaer; -import java.lang.invoke.TypeDescriptor.OfField; -import java.time.OffsetDateTime; import java.util.ArrayList; import javax.swing.JPanel; public abstract class BaseStack extends JPanel { + public final int IMAGE_WIDTH = 72; + public final int IMAGE_HIGHT = 96; + public final int STACK_HIGHT = 450; + private static final long serialVersionUID = 1L; private ArrayList stack = new ArrayList(); private final int OFFSET_VALUE = 20; diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 4ca99b8..4e9a08a 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -8,14 +8,14 @@ import javax.swing.event.MouseInputListener; public class MyMouseListener implements MouseInputListener { - private SaveStack save; + private SaveStack saveStack; private BaseStack tempStack; private BaseStack selectedStack; private Card tempCard; public MyMouseListener(SaveStack _save) { // TODO Auto-generated constructor stub - this.save = _save; + this.saveStack = _save; } @Override @@ -40,7 +40,7 @@ public class MyMouseListener implements MouseInputListener { tempCard = (Card) com; tempStack = (StartStack) com.getParent(); - if (save.stackIsEmpty()) { + if (saveStack.stackIsEmpty()) { // Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um if (!tempCard.isFaceUp()) { if (tempStack.peekLastCard().equals(tempCard)) { @@ -53,7 +53,7 @@ public class MyMouseListener implements MouseInputListener { // move all Cards below the selected Card to Save int index = tempStack.indexOfCard(tempCard); while (tempStack.stackSize() - 1 >= index) { - save.addCard(tempStack.removeLastCard()); + saveStack.addCard(tempStack.removeLastCard()); } selectedStack = tempStack; @@ -64,14 +64,14 @@ public class MyMouseListener implements MouseInputListener { if(selectedStack == null) { System.out.println("ERROR selectedStack in StartStack"); } - if(tempStack.cardCheck(tempStack.peekLastCard(), save.peekLastCard())) { - while(!save.stackIsEmpty()) { - tempStack.addCard(save.removeLastCard()); + if(tempStack.cardCheck(tempStack.peekLastCard(), saveStack.peekLastCard())) { + while(!saveStack.stackIsEmpty()) { + tempStack.addCard(saveStack.removeLastCard()); } } else { //Alles wieder auf den Ursprünglichen Stack packen - while(!save.stackIsEmpty()) { - selectedStack.addCard(save.removeLastCard()); + while(!saveStack.stackIsEmpty()) { + selectedStack.addCard(saveStack.removeLastCard()); } } diff --git a/src/main/java/solitaer/SaveStack.java b/src/main/java/solitaer/SaveStack.java index d95974f..3f423a2 100644 --- a/src/main/java/solitaer/SaveStack.java +++ b/src/main/java/solitaer/SaveStack.java @@ -11,7 +11,7 @@ public class SaveStack extends BaseStack { // TODO Auto-generated constructor stub super(); super.setLocation(_x, _y); - super.setSize(72, 450); + super.setSize(IMAGE_WIDTH, STACK_HIGHT); super.setOpaque(false); super.setLayout(null); } @@ -28,10 +28,10 @@ public class SaveStack extends BaseStack { super.paintComponent(g); if (stackIsEmpty()) { g.setColor(Color.pink); - g.fillRect(0, 0, this.getWidth(), 96); + g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); g.setColor(Color.black); - g.drawRect(0, 0, this.getWidth() - 1, 96 - 1); + g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1); } } diff --git a/src/main/java/solitaer/StartStack.java b/src/main/java/solitaer/StartStack.java index 28710e4..8f14ae6 100644 --- a/src/main/java/solitaer/StartStack.java +++ b/src/main/java/solitaer/StartStack.java @@ -8,14 +8,10 @@ public class StartStack extends BaseStack { private static final long serialVersionUID = 1L; - private final int IMAGE_WIDTH = 72; - private final int IMAGE_HIGHT = 450; - - public StartStack(int _x, int _y) { super(); super.setLocation(_x, _y); - super.setSize(IMAGE_WIDTH, IMAGE_HIGHT); + super.setSize(IMAGE_WIDTH, STACK_HIGHT); super.setOpaque(false); super.setLayout(null); } @@ -51,10 +47,10 @@ public class StartStack extends BaseStack { super.paintComponent(g); if (stackIsEmpty()) { g.setColor(Color.gray); - g.fillRect(0, 0, this.getWidth(), 96); + g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); g.setColor(Color.black); - g.drawRect(0, 0, this.getWidth()-1, 96-1); + g.drawRect(0, 0, this.getWidth()-1, IMAGE_HIGHT-1); } }