Chapter 10 Strings and Characters 581 95 container.add(
Chapter 10 Strings and Characters 581 95 container.add( statusLabel ); 96 97 setSize( 275, 120 ); // set window size 98 show(); // show window 99 } 100 101 // shuffle deck of cards with one-pass algorithm 102 public void shuffle() 103 { 104 currentCard = -1; 105 106 // for each card, pick another random card and swap them 107 for ( int first = 0; first < deck.length; first++ ) { 108 int second = ( int ) ( Math.random() * 52 ); 109 Card temp = deck[ first ]; 110 deck[ first ] = deck[ second ]; 111 deck[ second ] = temp; 112 } 113 114 dealButton.setEnabled( true ); 115 } 116 117 // deal one card 118 public Card dealCard() 119 { 120 if ( ++currentCard < deck.length ) 121 return deck[ currentCard ]; 122 else { 123 dealButton.setEnabled( false ); 124 return null; 125 } 126 } 127 128 // execute application 129 public static void main( String args[] ) 130 { 131 DeckOfCards app = new DeckOfCards(); 132 133 app.addWindowListener( 134 135 // anonymous inner class 136 new WindowAdapter() { 137 138 // terminate application when user closes window 139 public void windowClosing( WindowEvent windowEvent ) 140 { 141 System.exit( 0 ); 142 } 143 144 } // end anonymous inner class 145 146 ); // end call to addWindowListener 147 Fig. 10.21 Card dealing program (part 3 of 4). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01