here is a program code i want to create an application that create frame and write the string on it and when i click the close tab of frame it will close the frame please help me...its very urgent..

import java.awt.event.*;

class SampleFrame 
{
	SampleFrame(String title)
	{
		super(title);
		MyWindowAdapter adapter = new MyWindowAdapter(this);
		addWindowListner(adapter);
	}
	public void paint(Graphics g) 
	{
		g.drawString("This is in frame window", 10, 40);
	}
}
class MyWindowAdapter extends WindowAdapter 
{
	SampleFrame sampleFrame;
	public MyWindowAdapter(SampleFrame sampleFrame) 
	{
		this.sampleFrame = sampleFrame;
	}
	public void windowClosing(WindowEvent we) 
	{
		sampleFrame.show();
	}
}

class AppletFrame
{
	public static void main(String [] args)
	{
		SampleFrame s;
	}
}

Why did you need to pass 'this' to the MyWIndowAdapter? Also, why does your windowClosing() try to show the frame again? Just use System.exit(0) instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.