//Author: ^-^ Veerle ^-^ import java.awt.*; import java.awt.event.*; import javax.swing.*; //All credit for the card images goes to Asankhaya Sharma from planet source code. public class solitare extends JApplet implements ActionListener { private solitareWindow mainWindow; private Container frame; private JMenuBar menuBar; private JMenu menuOptions, menuCardBack; private JMenuItem menuItemCardBackSonic, menuItemCardBackBelgium, menuItemCardBackMouse, menuItemCardBackNemo, menuItemCardBackUK, menuItemCardBackVanessa; public void init() { menuBar = new JMenuBar(); menuOptions = new JMenu("Options"); menuCardBack = new JMenu("Card picture"); menuItemCardBackSonic = new JMenuItem("Sonic"); menuItemCardBackBelgium = new JMenuItem("Belgium Flag"); menuItemCardBackMouse = new JMenuItem("Dutch Mouse"); menuItemCardBackNemo = new JMenuItem("Finding Nemo"); menuItemCardBackUK = new JMenuItem("UK Flag"); menuItemCardBackVanessa = new JMenuItem("Vanessa Mae"); menuItemCardBackSonic.setActionCommand("0"); menuItemCardBackBelgium.setActionCommand("1"); menuItemCardBackMouse.setActionCommand("2"); menuItemCardBackNemo.setActionCommand("3"); menuItemCardBackUK.setActionCommand("4"); menuItemCardBackVanessa.setActionCommand("5"); menuItemCardBackSonic.addActionListener(this); menuItemCardBackBelgium.addActionListener(this); menuItemCardBackMouse.addActionListener(this); menuItemCardBackNemo.addActionListener(this); menuItemCardBackUK.addActionListener(this); menuItemCardBackVanessa.addActionListener(this); menuCardBack.add(menuItemCardBackSonic); menuCardBack.add(menuItemCardBackBelgium); menuCardBack.add(menuItemCardBackMouse); menuCardBack.add(menuItemCardBackNemo); menuCardBack.add(menuItemCardBackUK); menuCardBack.add(menuItemCardBackVanessa); mainWindow = new solitareWindow(); mainWindow.setSize(new Dimension(640, 600)); mainWindow.setBackground(new Color(75,141,221)); importPictures(); frame = getContentPane(); frame.add(mainWindow, BorderLayout.CENTER); this.setJMenuBar(menuBar); } private void importPictures () { String colour = "", title = ""; int counter = 0; //Cycle through all 52 cards Image[] imgCards = new Image[52]; //Array to store every playing card Image[] imgCardBack = new Image[6]; //Array to store all the card back images try { for (int suit = 0; suit < 4; suit++) //Loop 4 times (for each suit) { switch (suit) //Inspect current suit number { case 0: colour = "club"; break; //Have to put break to stop it executing the other statements case 1: colour = "spade"; break; case 2: colour = "heart"; break; case 3: colour = "diamond"; break; } for (int rank = 0; rank < 13; rank++) //Loop 13 times (for ace - king) { title = colour + Integer.toString(rank + 1); //Current title is the current suit + the rank number + 1 imgCards[counter] = dataManager.createImage(this, getParameter(title)); counter++; } } for (int card = 0; card < 6; card++) //Loop the number of card back images being supplied { title = "cardBack" + Integer.toString(card); imgCardBack[card] = dataManager.createImage(this, getParameter(title)); } } catch (Exception ex) { } mainWindow.setupCards(imgCards, imgCardBack); mainWindow.newGame(); } public void actionPerformed(ActionEvent e) { mainWindow.setCardBack(Integer.parseInt(e.getActionCommand())); } }