Search in sources :

Example 1 with CorruptFileException

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();
    }
}
Also used : CorruptFileException(CustomDecks.CorruptFileException) ImageIcon(javax.swing.ImageIcon) JLabel(javax.swing.JLabel) CustomDeck(CustomDecks.CustomDeck) IOException(java.io.IOException) Card(Cards.Card)

Aggregations

Card (Cards.Card)1 CorruptFileException (CustomDecks.CorruptFileException)1 CustomDeck (CustomDecks.CustomDeck)1 IOException (java.io.IOException)1 ImageIcon (javax.swing.ImageIcon)1 JLabel (javax.swing.JLabel)1