tailieunhanh - Ivor Horton’s Beginning Java 2, JDK 5 Edition phần 7

để họ không cần được biết đến hoặc có thể truy cập bên ngoài. Do đó, thích hợp nếu bạn xác định các đối tượng Node bởi một lớp bên trong tới các BinaryTree lớp. Tất cả các nút trong một cây nhị phân phải được khác nhau, nhưng bạn có thể cho phép các mặt hàng trùng lặp dữ liệu | Handling Events Handle window events protected void processWindowEvent WindowEvent e if dispose Release resources 0 Exit the program e Pass on the event private JMenuBar menuBar new JMenuBar Window menu bar File menu items private JMenuItem newItem openItem closeItem saveItem saveAsItem printItem Element menu items private JRadioButtonMenuItem lineItem rectangleItem circleItem Types curveItem textItem private JCheckBoxMenuItem redItem yellowItem Colors greenItem blueItem You add the call to enableEvents as the last in the constructor. Note that the statement that sets EXIT_ON_CLOSE as the close option for the window is commented out. You could delete the statement if you want. When you compile SketchFrame and run Sketcher again you ll be able to close the window as before and the program will shut down gracefully. However this time it s your method that s doing it. How It Works The additional import statements make the constants defined in the AWTEvent class and the WindowEvent class name available to your source file without the need to qualify them with the package names. You call enableEvents in the constructor with WINDOW_EVENT_MASK as the argument to enable window events. This enables all the window events represented by the WindowEvent class. An object of this class can represent one of a number of different window events that are each identified by an event ID which is a constant defined within the WindowEvent class. The event IDs for the WindowEvent class are Event ID Description WINDOW_OPENED The event that occurs the first time a window is made visible. WINDOW_CLOSING The event that occurs as a result of the close icon being selected or Close being selected from the window s system menu. WINDOW_CLOSED The event that occurs when the window has been closed. WINDOW_ACTIVATED The event that occurs when the window is activated obtains the focus in other words. When another GUI component .