WindowListener in Java AWT with Tutorial

Add window listener event in java with example: This WindowListener tutorial is to handle various window listeners using a sample program. And it is also a part of AWT event class. Different type of window listeners are available in Java. But in this java AWT tutorial, we have used window listeners like,

  • Window resize listener,
  • Window close listener.

Window listener in java, a window object is used to create a window with no border and no menu button on top or elsewhere and also create a window with menu bar and border. So it is possible to create multiple screens on same window.

Java Event Program:

[Useful: C Program Tutorials] & [IT Companies Details]

//Import statements
import java.awt.*;
import java.awt.event.*;
//Class definition
class OurWindow extends Frame
{
	public OurWindow(String title)
	{
		super(title);
		addWindowListener(new MyWindowListener());
		setSize(200,300);
		show();
	}
	public static void main(String args[])
	{
		new OurWindow("Window Listener");
	}
}
class MyWindowListener extends WindowAdapter
{
	public void windowClosing(WindowEvent w)
	{
		System.exit(0);
	}
	public void windowIconified(WindowEvent we)
	{
		System.out.println("Window minimized");
	}
}

SEE: All Examination Results & News