Placing a button on a Frame 感 Program MyFirstFrame 回 150 < 100 30 60 setLayout( null )i okButton new Button(oK")i okButton setBounds( 100, 150, 60, 30)i add( okButton i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13 - 6 Placing a Button on a Frame setLayout( null ); okButton = new Button( “OK” ); okButton.setBounds( 100, 150, 60, 30); add( oKButton ); 100 150 60 30
Handling action Events-Action Listener import java. awt event. *i class MyFirstFrame extends Frame implements ActionListener Declare MyF irstFrame as an ActionListene public MyFirstFrame() Register MyF irstFrame as the action listener of both buttons cancelButton addActionListener( this okButton addActionListener( this C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 13-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13 - 7 Handling Action Events - ActionListener import java.awt.event.*; class MyFirstFrame extends Frame implements ActionListener { . . . } public MyFirstFrame ( ) { . . . cancelButton.addActionListener( this ); okButton.addActionListener( this ); . . . } Declare MyFirstFrame as an ActionListener. Register MyFirstFrame as the action listener of both buttons