Chapter 10 Strings and Characters 573 36 37 (Apache web server)
Chapter 10 Strings and Characters 573 36 37 toChar = new JButton( “Convert digit to character” ); 38 39 toChar.addActionListener( 40 41 // anonymous inner class 42 new ActionListener() { 43 44 // handle toChar JButton event 45 public void actionPerformed( ActionEvent actionEvent ) 46 { 47 digit = Integer.parseInt( input.getText() ); 48 radix = 49 Integer.parseInt( radixField.getText() ); 50 JOptionPane.showMessageDialog( null, 51 “Convert digit to character: ” + 52 Character.forDigit( digit, radix ) ); 53 } 54 55 } // end anonymous inner class 56 57 ); // end call to addActionListener 58 59 container.add( toChar ); 60 61 toInt = new JButton( “Convert character to digit” ); 62 63 toInt.addActionListener( 64 65 // anonymous inner class 66 new ActionListener() { 67 68 // handle toInt JButton event 69 public void actionPerformed( ActionEvent actionEvent ) 70 { 71 String s = input.getText(); 72 c = s.charAt( 0 ); 73 radix = 74 Integer.parseInt( radixField.getText() ); 75 JOptionPane.showMessageDialog( null, 76 “Convert character to digit: ” + 77 Character.digit( c, radix ) ); 78 } 79 80 } // end anonymous inner class 81 82 ); // end call to addActionListener 83 84 container.add( toInt ); 85 86 setSize( 275, 150 ); // set the window size 87 show(); // show the window 88 } Fig. 10.18 Characterclass staticconversion methods (part 2 of 3). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01