Friday, September 3, 2010

java window closure

fact, had never written a bolg, listen to a teacher's recommendation today, learning is a continuous accumulation of, java a lot of things I want to learn, you may forget, but as long as you work, you did not record one day gains. One day you will succeed. close java window can achieve windowLinstener interfaces to achieve, achieve its adapter class windowadapter class, should be the interface of this class is just empty ...

In fact, had never written a bolg, listen to a teacher's recommendation today, learning is a continuous accumulation of, java a lot of things I want to learn, you may forget, but as long as you work, you did not record one day gains. One day you will succeed. close java window can achieve windowLinstener interfaces to achieve, achieve its adapter class windowadapter class, should be the interface of this class is just an empty implementation class, so we can inherit this class overrides the method that we need. Anonymous class can be achieved within the class:


import java.awt .*;

import java.awt.event .*;

public class TestWindowClose (

public static void main (String args []) (

new MyFrame55 ("MyFrame");

)

)

class MyFrame55 extends Frame (

MyFrame55 (String s) (

super (s);

setLayout (null);

setBounds (300, 300, 400, 300);

this.setBackground (new Color (204, 204, 255));

setVisible (true);

this.addWindowListener (new MyWindowMonitor ());// achieved through internal class

)

class MyWindowMonitor extends WindowAdapter (/ / In order to avoid written all the way. to succeed with a WindowAdapter

public void windowClosing (WindowEvent e) (/ / user tries to close the window system menu in the window call.

setVisible (false); / / This is not no little ah

System.exit (0);

)

)

)

Of course, in the swing as long as a setDefultClose ~ ~ ~ method of the

No comments:

Post a Comment