0

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;
	}
}

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Taywin
0

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.

Edited by Taywin: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.