ActionListener

P

petoeter

I created a

public class gegevens implements ActionListener {
gegevens() {
some code to create and add textfields,
buttons, ...

button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource == button1) {
textfield1 = setText("xx");
}
}

on an other file I have a

class b extends JPanel {
b() {
gegevens geg = new gegevens();
this.add(geg);
}
}
to use in a public class with different panels.


Eclipse seems happy with this, but when hitting the button, it won't
work.
What did I miss?

Thanks,
 
A

Andrew Thompson

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.
to use in a public class with different panels.

Eclipse seems happy with this,

<DWS>
Eclipse is happy, let us rejoice!
...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.
 
P

petoeter

Dear Andrew T.

Of course I added

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

otherwise eclipse would fire an error message.
That the reason why I added the frase : eclipse seems happy, just to
say that there is no code error.

Please don't react , have a beer or a girl , or do something about
your personal problems.
 
L

Lew

petoeter said:
Dear Andrew T.

Of course I added

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

otherwise eclipse would fire an error message.
That the reason why I added the frase : eclipse seems happy, just to
say that there is no code error.

Please don't react , have a beer or a girl , or do something about
your personal problems.

Instead of getting personal you should respond to what Andrew said. Did you
notice how much effort he put into providing you an SSCCE, something you were
not willing to do for the group?

Instead of the /ad hominem/ attack you should follow Andrew's suggestions. The
information you provided is useless to anyone who might wish to help you; your
reaction to being called to account for it dissuades that same audience from
doing so.

-- Lew
 
D

Daniel Pitts

I created a

public class gegevens implements ActionListener {
gegevens() {
some code to create and add textfields,
buttons, ...

button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource == button1) {
textfield1 = setText("xx");
}
}

on an other file I have a

class b extends JPanel {
b() {
gegevens geg = new gegevens();
this.add(geg);
}
}
to use in a public class with different panels.

Eclipse seems happy with this, but when hitting the button, it won't
work.
What did I miss?

Thanks,


try addActionListener instead.
 
S

Suffocate

Dear Andrew T.

Of course I added

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

otherwise eclipse would fire an error message.
That the reason why I added the frase : eclipse seems happy, just to
say that there is no code error.

Please don't react , have a beer or a girl , or do something about
your personal problems.

I would seriously recommend that you actually READ what Andrew T.
posted before you respond like a 7 year old, and you might find that
he's sorted out your problem. As Lew said, if you jump the gun, people
will be less likely to offer help in the future.

Let us know when you've got it working :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top