Folks:
Late in life I'm taking a Java language course at local comm. college. Also using 3 dif. ref. books and online tutorials at Sun.
Learning about Layout managers and trying to understand online examples. Using the snippets from online and trying to run the codes to view the created GUIs. Can get most to work, but ran into one where I can't figure out what the error condition means.
Most of the code in the snippets are just that, snippets. I have to add WindowListeners so that I can close the windows after viewing, and that's where this compile error is occurring. (Have done same in other snippets without problems.)
Following is the code:
Compile error (red phrase above) reads: No enclosing instance of BorderPanel is accessible. Must qualify the allocation with an enclosing instance of type BorderPanel (e.g. x.A()where x is an instance of BorderPanel).
P.S. If I comment out the WindowListener statement and WinCloser class, the code paints the GUI. But I have to use ctrl-alt-del to end the process. :-(
Would greatly appreciate any insight to what this means.
Thanks,
Vic
Late in life I'm taking a Java language course at local comm. college. Also using 3 dif. ref. books and online tutorials at Sun.
Learning about Layout managers and trying to understand online examples. Using the snippets from online and trying to run the codes to view the created GUIs. Can get most to work, but ran into one where I can't figure out what the error condition means.
Most of the code in the snippets are just that, snippets. I have to add WindowListeners so that I can close the windows after viewing, and that's where this compile error is occurring. (Have done same in other snippets without problems.)
Following is the code:
Code:
import java.awt.*;
import java.awt.event.*;
public class BorderPanel extends Panel
{
private static final Insets insets = new Insets(10, 10, 10, 10);
public Insets getInsets()
{
return insets;
}
public void paint(Graphics g)
{
Dimension size = getSize();
g.setColor(getBackground());
g.draw3DRect(5, 5, size.width-11, size.height-11, false);
}
public static void main(String[] args) {
Frame f = new Frame("Test");
BorderPanel p = new BorderPanel();
f.setLayout(new GridLayout(1,0));
f.setBackground(Color.lightGray);
f.addWindowListener[COLOR=red](new WinCloser())[/color];
p.setLayout(new GridLayout(1,0));
p.add(new Button("Hello"));
f.add(p);
f.setVisible(true);
f.pack();
}
class WinCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}
Compile error (red phrase above) reads: No enclosing instance of BorderPanel is accessible. Must qualify the allocation with an enclosing instance of type BorderPanel (e.g. x.A()where x is an instance of BorderPanel).
P.S. If I comment out the WindowListener statement and WinCloser class, the code paints the GUI. But I have to use ctrl-alt-del to end the process. :-(
Would greatly appreciate any insight to what this means.
Thanks,
Vic