Help with this small code please

Hi. I am trying to compile this code but get returned with this error. The code is:

package authen;

import javax.swing.*;

public class Authenticator extends javax.swing.JFrame{

JTextField username = new JTextField(15);

JPasswordField password = new JPasswordField(15);

JTextArea comments = new JTextArea(4, 15);

JButton ok = new JButton("OK");

JButton cancel = new JButton("Cancel");

public Authenticator() {

super("Account Information");

setSize(300, 220);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel pane = new JPanel();

JLabel usernameLabel = new JLabel("Username:");

JLabel passwordLabel = new JLabel("Password:");

JLabel commentsLabel = new JLabel("Comments:");

comments.setLineWrap(true);

comments.setWrapStyleWord(true);

pane.add(usernameLabel);

pane.add(username);

pane.add(passwordLabel);

pane.add(password);

pane.add(commentsLabel);

pane.add(comments);

pane.add(ok);

pane.add(cancel);

add(pane);

setVisible(true);

}

public static void main(String[] args) {

Authenticator auth = new Authenticator();

}

}

The error is :

init:

deps-jar:

compile:

run:

java.lang.Error: Do not use authen.Authenticator.add() use authen.Authenticator.getContentPane().add() instead

at javax.swing.JFrame.createRootPaneException(JFrame.java:465)

at javax.swing.JFrame.addImpl(JFrame.java:491)

at java.awt.Container.add(Container.java:307)

at authen.Authenticator.<init>(Authenticator.java:43)

at authen.Authenticator.main(Authenticator.java:50)

Exception in thread "main"

Java Result: 1

BUILD SUCCESSFUL (total time: 1 second)

What am i doing wrong?

[1848 byte] By [the_infamous_dona] at [2007-10-2 17:23:46]
# 1
You're failing to obey the error message. It tells you precisely what to do to fix the problem.
YAT_Archivista at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...
# 2
That does not work.
the_infamous_dona at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...
# 3
> That does not work.What does not work?
annie79a at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...
# 4
> > That does not work.> > What does not work?That.
annie79a at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...
# 5
I tried to edit the code with what was returned. Can someone tell me how to edit my code to make it compile correctly please?
the_infamous_dona at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...
# 6
change pane to a container like soContainer pane = getContentPane();and get rid of this line.add(pane);
kefgolfsa at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...
# 7

> I tried to edit the code with what was returned. Can

> someone tell me how to edit my code to make it

> compile correctly please?

1) Make sure you are looking at the right code.

2) Edit appropriately.

3) Save

4) Compile

If that doesn't work I can only guess you would have to start another 2 or 3 threads on this exciting topic to get it resolved. Good luck.

kefgolfsa at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...
# 8
> > > That does not work.> > > > What does not work?> > That.Then use this. :P
annie79a at 2007-7-13 18:39:59 > top of Java-index,Java Essentials,Java Programming...