Hi All,
I want to know how to use
both JButtons and JRadioButtons
in the same program since they both access the
same:
"public void actionPerformed(ActionEvent event){ }"
I have researched demos and they show how
to do one type of button or the other, but not
both types in the same program. Is it a case of
sorting out which one is sending what
within that"
"public void actionPerformed(ActionEvent event){ }"
or is there some other solution?
TIA,
bH
Eric Sosman - 05 Feb 2010 21:57 GMT
> Hi All,
> I want to know how to use
[quoted text clipped - 9 lines]
> "public void actionPerformed(ActionEvent event){ }"
> or is there some other solution?
First, when you set up your button (any kind), you give
it whatever ActionListener you like. Each button can have
its very own ActionListener with its very own actionPerformed()
method.
Second, if you want several buttons to share the same
ActionListener and still want to make decisions based on which
button was activated, you can use the getSource() method of
the ActionEvent object. (The ActionEvent has methods to fetch
other kinds of information, too.)

Signature
Eric Sosman
esosman@ieee-dot-org.invalid
The87Boy - 05 Feb 2010 22:03 GMT
> Hi All,
> I want to know how to use
[quoted text clipped - 11 lines]
> TIA,
> bH
On the JRadioButtons and the JButtons you can make use of
addActionListener e.g.
JRadioButton button1 = new JRadioButton();
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// The code goes here
}
});
bH - 05 Feb 2010 22:39 GMT
> > Hi All,
> > I want to know how to use
[quoted text clipped - 24 lines]
>
> - Show quoted text -
Hi,
I appreciate your prompt responses.
I will now work on it as you have suggested.
Thanks,
bH