580 Strings and Characters Chapter 10 42 dealButton.addActionListener( (Cool web site)

580 Strings and Characters Chapter 10 42 dealButton.addActionListener( 43 44 // anonymous inner class 45 new ActionListener() { 46 47 // deal one card 48 public void actionPerformed( ActionEvent actionEvent ) 49 { 50 Card dealt = dealCard(); 51 52 if ( dealt != null ) { 53 displayField.setText( dealt.toString() ); 54 statusLabel.setText( “Card #: ” + currentCard ); 55 } 56 else { 57 displayField.setText( 58 “NO MORE CARDS TO DEAL” ); 59 statusLabel.setText( 60 “Shuffle cards to continue” ); 61 } 62 } 63 64 } // end anonymous inner class 65 66 ); // end call to addActionListener 67 68 container.add( dealButton ); 69 70 shuffleButton = new JButton( “Shuffle cards” ); 71 shuffleButton.addActionListener( 72 73 // anonymous inner class 74 new ActionListener() { 75 76 // shuffle deck 77 public void actionPerformed( ActionEvent actionEvent ) 78 { 79 displayField.setText( “SHUFFLING …” ); 80 shuffle(); 81 displayField.setText( “DECK IS SHUFFLED” ); 82 } 83 84 } // end anonymous inner class 85 86 ); // end call to addActionListener 87 88 container.add( shuffleButton ); 89 90 displayField = new JTextField( 20 ); 91 displayField.setEditable( false ); 92 container.add( displayField ); 93 94 statusLabel = new JLabel(); Fig. 10.21 Card dealing program (part 2 of 4). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply