tailieunhanh - murachs Java SE 2010 phần 7

Cuốn sách này là không chắc chắn người đó là để dành cho. Nó nói nó là dành cho đào tạo và tham khảo. Nó không phải là một cuốn sách đào tạo và như là một cuốn sách refence, nhiều lá để được mong muốn. Nếu bạn biết bất cứ điều gì về | Chapter 15 How to get started with Swing 485 The control menu for a frame The setDefaultCloseOperation method of the JFrame class Method Description setDefaultCloseOperation action Sets the default close action for the frame. Constants to set the default close operation Constant Description ON CLOSE Exits the application when the user closes the window. Provides no default action so the program must explicitly handle the closing event as described in chapter 17. Hides the frame when the user closes the window. This is the default action. Hides and disposes of the frame when the user closes the window. A class that defines a closeable frame class FutureValueFrame extends JFrame . . . _ . _ . public FutureValueFr ame . . . setTitie Future Value Calculator setBounds 267 200 267 200 setDefaultCloseOperation . Description To close a frame the user can click on the Close button in the upper right comer of the frame press Alt F4 or pull down the control menu and select the Close command. When you create an instance of a frame in an application the frame runs in its own thread. As a result the frame thread will continue to run even after the main method terminates. The application doesn t exit until the frame thread terminates. You can use the setDefaultCloseOperation method to cause the application to exit when the user closes the frame. Alternatively you can add event-handling code to respond to the windowClosing event. You ll learn how to do that in chapter 17. Figure 15-5 How to set the default close operation 486 Section 4 GUI programming with Java How to center a frame using the Toolkit class Figure 15-6 shows how to get the height and width of the current user s screen in pixels. To do that you can use the Toolkit and Dimension classes of the package. Then you can use the setLocation method to set the position of a frame relative to