public class QuickStart4f extends JFrame {
JPanel myjpdraw = new JPanel();
JButton myjbdrawnow = new JButton("DRAW NOW");
JLabel j1 = new JLabel("Point 1 : ");
JTextField mytf1 = new JTextField("", 5);
JTextField mytf2 = new JTextField("", 5);
JLabel j2 = new JLabel("Point 2 : ");
JTextField mytf3 = new JTextField("", 5);
JTextField mytf4 = new JTextField("", 5);
public double pt11;
public double pt12;
public double pt21;
public double pt22;
myjpdraw.add(j1);
myjpdraw.add(mytf1);
myjpdraw.add(mytf2);
myjpdraw.add(j2 );
myjpdraw.add(mytf3);
myjpdraw.add(mytf4);
myjpdraw.add(myjbdrawnow);
getContentPane().add(myjpdraw,BorderLayout.SOUTH);
myjbdrawnow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
pt11 = Double.parseDouble(mytf1.getText());
pt12 = Double.parseDouble(mytf2.getText());
pt21 = Double.parseDouble(mytf3.getText());
pt22 = Double.parseDouble(mytf4.getText());
}
});
System.out.print(pt11);
}
}
When I am retrieving the value pt11 from the actionperformed method and trying to print it, it gives me a null value. How to get the value that has been entered in the textfield and access it outside the button actionperformed method?