Re: ActionListener
On Mar 25, 9:20 pm, "petoeter" <pieters-patr...@freegates.be> wrote:
I created a
(snip rubbish)
Please do not wast your time, and our bandwdih
posting such tripe. As far as I can tell,
(from the little you posted) that code could
not compile.
In future, please post neatly formatted SSCCE's.
<http://www.physci.org/codes/sscce.html>
to use in a public class with different panels.
Eclipse seems happy with this,
<DWS>
Eclipse is happy, let us rejoice!
</DWS>
...but when hitting the button, it won't
work.
What did I miss?
<sscce>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class gegevens extends JPanel implements ActionListener {
TextField textfield1 = new TextField();
JButton button1 = new JButton("Press Me");
gegevens() {
//some code to create and add textfields,
//buttons, ...
add(button1);
add(textfield1);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button1) {
textfield1.setText("xx");
}
}
public static void main(String args[]) {
JOptionPane.showMessageDialog(null, new b());
}
}
class b extends JPanel {
b() {
gegevens geg = new gegevens();
this.add(geg);
}
}
</sscce>
Andrew T.