I want to add a JButton to my script but for some reason I can't add an Action Listener to it. Here's my code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class NewJFrame extends javax.swing.JFrame {
public static void main(String args[]) {
jButton1.addActionListener(new ActionListener() { //ERROR here
public void actionPerformed(ActionEvent le) {
//Do stuff
}
});
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
}
I get the following error:
non-static variable JButton1 cannot be referenced from a static context
Any help is appreciated, as I am new to the whole GUI stuff