Advertisement
jdalbey

Card Sorter skeleton

May 28th, 2014
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.26 KB | None | 0 0
  1.  
  2. /**
  3.  * A simple card sorting game to demonstrate Swing panels and buttons.
  4.  * Seven random cards are given to the player.  The cards must be clicked
  5.  * on in order from smallest to largest.  
  6.  * @author jdalbey
  7.  */
  8. public class CardSorter extends javax.swing.JFrame
  9. {
  10.     public final static String path = "images/";  /* directory of images */
  11.     private static final int FRAME_WIDTH = 450;
  12.     private static final int FRAME_HEIGHT = 400;    
  13.    
  14.     public CardSorter()
  15.     {
  16.         super("Card Sorter");
  17.         setSize(FRAME_WIDTH, FRAME_HEIGHT);        
  18.         // initialize the application
  19.  
  20.  
  21.     }
  22.  
  23.     /** This method is called from within the constructor to
  24.      *  initialize the form.  It creates all the components and adds
  25.      *  them to the frame.
  26.      */
  27.     private void initComponents() {
  28.         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  29.         // Create the panel for the player's hand.
  30.         // Create the panel for the playing area (table)
  31.         // Create the panel for the buttons and score
  32.         // Create the help button and listener
  33.         // Create the restart button and listener
  34.         // Assemble all the components and panels
  35.  
  36.         pack();
  37.     }
  38.     /* Create a the player's hand of random cards.*/
  39.     private final void createHandPanel()
  40.     {
  41.         // Loop for seven cards
  42.             // pick a random card and add it to the hand
  43.             // Create a button representing the card
  44.             // Add the button to the panel
  45.            
  46.         validate();
  47.         repaint();
  48.     }
  49.  
  50.     /* Create a button with a card image, and position number as the action command.
  51.      * @param pos the position of this card from left to right in the hand (zero-based)
  52.      * @param cardName the filename of the image for this card
  53.      * @return the completed button with the image of the card
  54.      */
  55.     private JButton createCardButton(int pos, String cardName)
  56.     {
  57.     }
  58.    
  59.    
  60.     /** Handle a click of a card in the player's hand */
  61.     private void cardClicked(java.awt.event.ActionEvent evt)
  62.     {
  63.         // Turn off the button's visibility
  64.         // Get the icon from the button
  65.         // Make a label from the icon
  66.         // Add the label to the table panel
  67.         // extract the card's position from the action command
  68.         // get the card from the hand and add it to the table
  69.         // Are the cards on the table in correct order?
  70.             // Is the table full?
  71.                 // JOptionPane show a win message, increment won count
  72.         // else
  73.             // JOptionPane show a lose message, increment lost count
  74.         // update the text in the scores label
  75.        
  76.         validate();
  77.         repaint();
  78.     }
  79.  
  80.     /** Determine if the cards on the table are in the correct order */
  81.     private boolean isOrderedTable()
  82.     {
  83.     }
  84.     /**
  85.      * @param args the command line arguments
  86.      */
  87.     public static void main(String args[])
  88.     {
  89.     }
  90.     private javax.swing.JPanel handPanel;
  91.     private javax.swing.JPanel tablePanel;
  92.     private javax.swing.JButton btnRestart;
  93.     private javax.swing.JButton btnHelp;
  94.     private javax.swing.JLabel lblScores;
  95.     private javax.swing.JPanel scorePanel;
  96.     private String[] cardNames = {
  97. "hearts-a-75.png", "hearts-2-75.png", "hearts-3-75.png", "hearts-4-75.png", "hearts-5-75.png", "hearts-6-75.png",
  98. "hearts-7-75.png", "hearts-8-75.png", "hearts-9-75.png", "hearts-10-75.png", "hearts-j-75.png", "hearts-q-75.png",
  99. "hearts-k-75.png", "clubs-a-75.png", "clubs-2-75.png", "clubs-3-75.png", "clubs-4-75.png", "clubs-5-75.png",
  100. "clubs-6-75.png", "clubs-7-75.png", "clubs-8-75.png", "clubs-9-75.png", "clubs-10-75.png", "clubs-j-75.png",
  101. "clubs-q-75.png", "clubs-k-75.png", "diamonds-a-75.png", "diamonds-2-75.png", "diamonds-3-75.png", "diamonds-4-75.png",
  102. "diamonds-5-75.png", "diamonds-6-75.png", "diamonds-7-75.png", "diamonds-8-75.png", "diamonds-9-75.png", "diamonds-10-75.png",
  103. "diamonds-j-75.png", "diamonds-q-75.png", "diamonds-k-75.png", "spades-a-75.png", "spades-2-75.png", "spades-3-75.png",
  104. "spades-4-75.png", "spades-5-75.png", "spades-6-75.png", "spades-7-75.png", "spades-8-75.png", "spades-9-75.png",
  105. "spades-10-75.png", "spades-j-75.png", "spades-q-75.png", "spades-k-75.png"
  106. };
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement