English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi could anyone explain this program to me please.

public class WindowInnerDemo extends Frame
{
public WindowInnerDemo()
{
addWindowListener(new MyWindowInner(this)); //Line1
}
public void paint(Graphics g)
{
g.drawString("This is a frame",10,100);
}
p.s.v.m(String args[])
{
WindowInnerDemo w=new WindowInnerDemo();
w.setTitle("Myframe");
w.setVisible(true);
w.setSize(400,400);
w.show();
}
class MyWindowInner extends WindowAdapter
{
WindowInnerDemo w;
MyWindowInner(WindowInnerDemo w1)
{
w=w1;
}
public void windowClosing(WindowEvent we)
{
w.setVisible(false);
}
}
}

What is the meaning of new MyWindowInner(this) in Line 1 comment.

2007-07-10 14:09:01 · 2 answers · asked by anusha 1 in Computers & Internet Programming & Design

2 answers

It creates an instance of the Inner class, that references the current instance of the WindowInnerDemo class.

(Each instance of an inner class must know the instance of the "outer" class that it belongs to, and that is an implied argument to the constructor.)

2007-07-10 14:32:38 · answer #1 · answered by McFate 7 · 0 0

For getting homework help there are better websites like http://getafreelnacer.com/

2007-07-11 04:43:32 · answer #2 · answered by Anonymous · 0 1

fedest.com, questions and answers