Need Help Fixing Error, Please.
Hi!
I'm very new to Java and I am trying to write a very simple applet which will display a Frame (which will have the ability to close using the "X" in the upper right corner) and a simple title in the Frame title bar. I have narrowed it down to one error. My code is as follows:
import java.awt.event.*;
publicclass WeWon
{
publicstaticvoid main(String [] args)
{
Frame aFrame =new Frame("We Won!");
aFrame.setSize(400, 300);
aFrame.setBackground(Color.black);
aFrame.setVisible(true);
}
publicvoid WeWonAboutToCloseextends Frame
implements WindowListener
{
public aFrameClosing(String str)
{
super(str);
addWindowListener(this);
}
public WeWonAdapterextends WindowAdapter
{
publicvoid windowClosing(WindowEvent e)
}
System.exit(0);
}
}
The error I receive is as follows:
C:\jdk131\WeWon.java:27:'(' expected
publicvoid WeWonAboutToCloseextends Frame
^
I think I know why I am getting the error ( I think I need to have a String arg after the name of the method) but I don't know how to go about this and still achieve what I want from this applet.
Thanks for any insight.
Susan
[2396 byte] By [
SusanLM] at [2007-9-27 1:43:10]

Is this what you're looking for:
import java.awt.*;
import java.awt.event.*;
public class WeWon {
public static void main(String [] args) {
Frame aFrame = new Frame("We Won!");
aFrame.setSize(400, 300);
aFrame.setBackground(Color.black);
aFrame.setVisible(true);
aFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
V.V.
> Is this what you're looking for:
>
> V.V.
That's EXACTLY what I was looking for! How did I go so wrong?
Now that I see it written, I can understand it perfectly. But I always have a hard time writing code myself. Is this a common phenomenon or am I just odd?
One thing I don't understand completely, however, is the use of the ");" on this line:
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
I've seen it written a number of times in other code and for the life of me, I can see no reason to insert a ");" at that point in the code. Can you explain?
Thanks again!
Susan
What is used here is referred to as an inner class. Here are the benefits of using an inner class:
1) An object of an inner class can acces the implementation of the object that created it.
2) It can be hidden from other classes.
3) It is a convenient way of writing event-driven programs.
The reason for the ); is because it is part of the statement aFrame.addWindowListener( which must be terminated.
V.V.