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?

