Chapter 13 GUI Objects and Event-Driven Programming 2000 McGraw-Hl‖ Introduction to Object-Oriented Programming with Java-Wu Chapter 13-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13 - 1 Chapter 13 GUI Objects and Event-Driven Programming
Chapter 13 Objectives After, you have read and studied this chapter, you shoula be able to Write GUI application programs using Frame, Dialog, and Button objects from the java. awt package e Write Gui application programs with menus using Menu MenuItem and menu bar objects from the java. awt package e Write event-driven programs using Java's delegation based event model e Write GUI application programs that process mouse events e Understand how the sketchPad class introduced in Chapter 1 is implemented e Run applets as applications C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13 - 2 Chapter 13 Objectives After you have read and studied this chapter, you should be able to Write GUI application programs using Frame, Dialog, and Button objects from the java.awt package. Write GUI application programs with menus using Menu, MenuItem, and MenuBar objects from the java.awt package. Write event-driven programs using Java’s delegationbased event model. Write GUI application programs that process mouse events. Understand how the SketchPad class introduced in Chapter 1 is implemented. Run applets as applications
GUi Objects ATesting Menu 回区 MenuBar File Edit Cut Menu Menuitem Paste Let's Play HiLo Enter your guess TextField Dialog Label You can make up to 6 guesses Let' s have fun with the hilo game Button Guess Frame C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 13-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13 - 3 GUI Objects MenuBar MenuItem TextField Label Button Frame Dialog Menu
Interacting with Buttons r Place two buttons labeled oK and cancel on a frame r Change the frame title when either button is clicked 感 You clicked oK 回x CANCEL myfirstframe C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 13-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13 - 4 Interacting with Buttons Place two buttons labeled OK and CANCEL on a frame. Change the frame title when either button is clicked
Creating a Frame object 150 200 300 import Java. awt private static final int FRAME WIDTH 300; private static final int FRAME HEIGHT 200 private static final int FRAME X ORIGIN private static final int FRAME Y ORIGIN= 250i setsize FRAME WIDTH, FRAME HEIGHT rEsizable( fa etritle (Program MyFirstErame")i setlocation( FRAME X ORIGIN, FRAME Y ORIGIN C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 13 - 5 Creating a Frame Object import java.awt.*; class MyFirstFrame extends Frame { private static final int FRAME_WIDTH = 300; private static final int FRAME_HEIGHT = 200; private static final int FRAME_X_ORIGIN = 150; private static final int FRAME_Y_ORIGIN = 250; public MyFirstFrame( ) { setSize ( FRAME_WIDTH, FRAME_HEIGHT ); setResizable ( false ); setTitle ( "Program MyFirstFrame" ); setLocation ( FRAME_X_ORIGIN, FRAME_Y_ORIGIN ); } } 150 250 300 200