use of CustomDecks.CorruptFileException in project cardgame1 by joey101937.
the class DeckLoaderScratch method loadSelected.
/**
* Loads the deck corresponding to what the combobox has selected.
*/
private void loadSelected() {
try {
for (JLabel jl : cardLabels) {
panel.remove(jl);
}
cardLabels.clear();
chosenDeck = new CustomDeck(savedDecks.get(combo.getSelectedIndex()));
deckTitleLabel.setText(chosenDeck.deckName);
deckTitleLabel.setIcon(new ImageIcon(chosenDeck.deckClass.getHeroPortraitPath()));
int i = 0;
for (Card c : chosenDeck.deck) {
JLabel cardLabel = new CardLabel(c, this);
cardLabel.setSize(300, 22);
cardLabel.setLocation(20, 200 + 22 * i);
panel.add(cardLabel);
cardLabels.add(cardLabel);
i++;
}
if (!chosenDeck.isValid()) {
System.out.println(chosenDeck.diagnose());
isValidLabel.setText("Illegal Deck");
isValidLabel.setIcon(new ImageIcon(Main.assets + "redXsmall.png"));
} else {
isValidLabel.setIcon(new ImageIcon(Main.assets + "checkmarkSmall.png"));
isValidLabel.setText("Confirm");
}
panel.repaint();
core.setVisible(true);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "IO Error");
ex.printStackTrace();
} catch (CorruptFileException ex) {
JOptionPane.showMessageDialog(null, "Deck could not be loaded without error: " + ex.getMessage());
ex.printStackTrace();
}
}
Aggregations