Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to deselct a radio button using another button (with java) ?

Update:

java application

Update 2:

prowler java application

JRadioButton rb = new JRadioButton() ;

JButton b = new JButton() ;

i know how to add a a listener but how to deselect the "rb" using the "b" button ??

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    You really have two choices here.

    1. You can make a separate class that implements the ActionListener interface that has a constructor that takes a JRadioButton. Construct the listener for the button, passing the JRadioButton to the listener, then add the listener to the JButton using the addActionListener method.

    2. You can do an inline definition of the action listener when you create the JButton. The important thing in this approach is that the JRadioButton must be a member variable of the class where you are creating the JButton. When you define the ActionListener in-line it gains access to the member variables of the class where it's defined.

    Example:

    b.addActionListener( new ActionListener(){

    public void actionPerformed( Event e )

    {

    rb.setSelected(false);

    }

    });

  • 1 decade ago

    just add an action listiner that is watched by the radio button.

  • 1 decade ago

    Create a button and give it a value of reset.... like this....

    //<input type="Reset" value="Reset" name="Reset">//

    without the //'s

    Hope this helps

    Ok then try this one....

    //<h:command_button id="reset" action="reset" label="Reset"

    commandName="reset" />//

    again without the //'s on either side

Still have questions? Get your answers by asking now.