Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2010

Tip: Looking for answers? Try searching our database.

using JButton and JRadioButton

Thread view: 
bH - 05 Feb 2010 21:24 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.