G
George
Dear All,
I am trying to use JFrame and JTextField, so that whenever a button is
clicked a message box will come up with the contents of the textfield.
These are defined as follows:
class Test extends JFrame implements ActionListener {
Jpanel p1 = new JPanel();
JTextField jtf = new JTextField();
p1.add(jtf);
this.add(p1);
JButton jb = new JButton("Click Me!");
this.add(jb);
jb.addActionListener(this);
(of course these commands are within an initialisation method)
The action listener is implemented as follows:
public void actionPerformed(ActionEvent e){
System.out.println(jtf.getText());
}
However, this gives me the error message that jtf can not be resolved. Is
it because it is inside a panel and how can I reference the panel and then
the textfield inside?
I look forward to hearing from you soon.
Many thanks in advance.
George
I am trying to use JFrame and JTextField, so that whenever a button is
clicked a message box will come up with the contents of the textfield.
These are defined as follows:
class Test extends JFrame implements ActionListener {
Jpanel p1 = new JPanel();
JTextField jtf = new JTextField();
p1.add(jtf);
this.add(p1);
JButton jb = new JButton("Click Me!");
this.add(jb);
jb.addActionListener(this);
(of course these commands are within an initialisation method)
The action listener is implemented as follows:
public void actionPerformed(ActionEvent e){
System.out.println(jtf.getText());
}
However, this gives me the error message that jtf can not be resolved. Is
it because it is inside a panel and how can I reference the panel and then
the textfield inside?
I look forward to hearing from you soon.
Many thanks in advance.
George