610 Graphics and Java2D Chapter 11 21 (How to cite a web site) container

610 Graphics and Java2D Chapter 11 21 container = getContentPane(); 22 container.setLayout( new FlowLayout() ); 23 24 // set up changeColorButton and register its event handler 25 changeColorButton = new JButton( “Change Color” ); 26 27 changeColorButton.addActionListener( 28 29 // anonymous inner class 30 new ActionListener() { 31 32 // display JColorChooser when user clicks button 33 public void actionPerformed( ActionEvent event ) 34 { 35 color = JColorChooser.showDialog( 36 ShowColors2.this, “Choose a color”, color ); 37 38 // set default color, if no color is returned 39 if ( color == null ) 40 color = Color.lightGray; 41 42 // change content pane’s background color 43 container.setBackground( color ); 44 } 45 46 } // end anonymous inner class 47 48 ); // end call to addActionListener 49 50 container.add( changeColorButton ); 51 52 setSize( 400, 130 ); 53 setVisible( true ); 54 } 55 56 // execute application 57 public static void main( String args[] ) 58 { 59 ShowColors2 application = new ShowColors2(); 60 61 application.setDefaultCloseOperation( 62 JFrame.EXIT_ON_CLOSE ); 63 } 64 65 } // end class ShowColors2 Fig. 11.6 Demonstrating the JColorChooserdialog (part 2 of 3). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply