I am trying to create JLabels to display a cart from a store in scrabble. When the cart is empty it should read "Cart is empty." and when it isn't it should list the contents in a list. The following is the code I have used to do this.
public void reset(){
removeAll();
}
public void update(){
reset();
JLabel cartHeader = new JLabel("<html><br><b>Current Player's Tile Cart</b></html>", JLabel.CENTER);
add(cartHeader);
ArrayList<SpecialTile> tileCart = gameStore.getTileCart();
if(tileCart.size() == 0){
JLabel emptyCart = new JLabel("<html><br><br>Cart is currently empty.</html>", JLabel.CENTER);
add(emptyCart);
}else{
System.out.println("tileCart size: "+tileCart.size());
for(SpecialTile currentTile : tileCart){
JLabel tileLabel = new JLabel("", JLabel.CENTER);
if(currentTile.getClass().equals(BoomTile.class)){
tileLabel.setText("BoomTile - "+exampleBoom.tilePrice());
}else if(currentTile.getClass().equals(ReverseOrder.class)){
tileLabel.setText("ReverseOrderTile - "+exampleReverse.tilePrice());
}else if(currentTile.getClass().equals(NegativePoints.class)){
tileLabel.setText("NegativePointsTile - "+exampleNegative.tilePrice());
}else if(currentTile.getClass().equals(PersonalTile.class)){
tileLabel.setText("ShareTile - "+exampleShare.tilePrice());
}else if(currentTile.getClass().equals(UnknownTile.class)){
tileLabel.setText("UnknownTile - "+exampleUnknown.tilePrice());
}
add(tileLabel);
}
}
JButton purchaseButton = new JButton("Purchase");
add(purchaseButton);
}
The issue I'm running into is that instead of replacing the text with the different tiles in the cart it always reads that the cart is empty.
Aucun commentaire:
Enregistrer un commentaire