Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A simple card sorting game to demonstrate Swing panels and buttons.
- * Seven random cards are given to the player. The cards must be clicked
- * on in order from smallest to largest.
- * @author jdalbey
- */
- public class CardSorter extends javax.swing.JFrame
- {
- public final static String path = "images/"; /* directory of images */
- private static final int FRAME_WIDTH = 450;
- private static final int FRAME_HEIGHT = 400;
- public CardSorter()
- {
- super("Card Sorter");
- setSize(FRAME_WIDTH, FRAME_HEIGHT);
- // initialize the application
- }
- /** This method is called from within the constructor to
- * initialize the form. It creates all the components and adds
- * them to the frame.
- */
- private void initComponents() {
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- // Create the panel for the player's hand.
- // Create the panel for the playing area (table)
- // Create the panel for the buttons and score
- // Create the help button and listener
- // Create the restart button and listener
- // Assemble all the components and panels
- pack();
- }
- /* Create a the player's hand of random cards.*/
- private final void createHandPanel()
- {
- // Loop for seven cards
- // pick a random card and add it to the hand
- // Create a button representing the card
- // Add the button to the panel
- validate();
- repaint();
- }
- /* Create a button with a card image, and position number as the action command.
- * @param pos the position of this card from left to right in the hand (zero-based)
- * @param cardName the filename of the image for this card
- * @return the completed button with the image of the card
- */
- private JButton createCardButton(int pos, String cardName)
- {
- }
- /** Handle a click of a card in the player's hand */
- private void cardClicked(java.awt.event.ActionEvent evt)
- {
- // Turn off the button's visibility
- // Get the icon from the button
- // Make a label from the icon
- // Add the label to the table panel
- // extract the card's position from the action command
- // get the card from the hand and add it to the table
- // Are the cards on the table in correct order?
- // Is the table full?
- // JOptionPane show a win message, increment won count
- // else
- // JOptionPane show a lose message, increment lost count
- // update the text in the scores label
- validate();
- repaint();
- }
- /** Determine if the cards on the table are in the correct order */
- private boolean isOrderedTable()
- {
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[])
- {
- }
- private javax.swing.JPanel handPanel;
- private javax.swing.JPanel tablePanel;
- private javax.swing.JButton btnRestart;
- private javax.swing.JButton btnHelp;
- private javax.swing.JLabel lblScores;
- private javax.swing.JPanel scorePanel;
- private String[] cardNames = {
- "hearts-a-75.png", "hearts-2-75.png", "hearts-3-75.png", "hearts-4-75.png", "hearts-5-75.png", "hearts-6-75.png",
- "hearts-7-75.png", "hearts-8-75.png", "hearts-9-75.png", "hearts-10-75.png", "hearts-j-75.png", "hearts-q-75.png",
- "hearts-k-75.png", "clubs-a-75.png", "clubs-2-75.png", "clubs-3-75.png", "clubs-4-75.png", "clubs-5-75.png",
- "clubs-6-75.png", "clubs-7-75.png", "clubs-8-75.png", "clubs-9-75.png", "clubs-10-75.png", "clubs-j-75.png",
- "clubs-q-75.png", "clubs-k-75.png", "diamonds-a-75.png", "diamonds-2-75.png", "diamonds-3-75.png", "diamonds-4-75.png",
- "diamonds-5-75.png", "diamonds-6-75.png", "diamonds-7-75.png", "diamonds-8-75.png", "diamonds-9-75.png", "diamonds-10-75.png",
- "diamonds-j-75.png", "diamonds-q-75.png", "diamonds-k-75.png", "spades-a-75.png", "spades-2-75.png", "spades-3-75.png",
- "spades-4-75.png", "spades-5-75.png", "spades-6-75.png", "spades-7-75.png", "spades-8-75.png", "spades-9-75.png",
- "spades-10-75.png", "spades-j-75.png", "spades-q-75.png", "spades-k-75.png"
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement