package test2;
public class NewJFrame extends javax.swing.JFrame {
private static void valueGen() {
String x = jTextField1.getText();
System.out.println(x);
}
public NewJFrame() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("Hello");
}
public static void main(String args[]) {
valueGen();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1;
}
I have a program as shown above.
I need to access the value of jTextField1 from the function valueGen().
But I get the error:
non-static variable cannot be referenced from static context
What should I do in order to access the value of jTextField1 from valueGen()?