Results 1 to 3 of 3
  1. #1
    Adithya is offline Member
    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0

    Default how selected radio button of text check with another string of array??

    Java Code:
    ButtonGroup bg=new ButtonGroup();
    JRadioButton  choice1=new JRadioButton(); 
    JRadioButton  choice2=new JRadioButton();
     JRadioButton choice3=new JRadioButton();
    JRadioButton  choice4=new JRadioButton();
                    bg.add(choice1);
                    bg.add(choice2);
                    bg.add(choice3);
                    bg.add(choice4);
    here i coded out my radio button..i am confused how to get the selected radio button of string and match with another array of String...
    please help me ...
    kindly code it out a single line..

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default Re: how selected radio button of text check with another string of array??

    u have to do like this for getting the selected radiobutton text.

    Ex:
    1. choice1.setActionCommand("choice1");

    // Register an action listener for the radio buttons.
    RadioListener obj= RadioListener();
    choice1.addActionListener(obj);

    finally implement this below for activating..whever u select one radiobutton,its text can be retreived
    class RadioListener implements ActionListener {

    public void actionPerformed(ActionEvent e) {
    String txt =e.getActionCommand();
    //u can retreive and compare to ur array.
    }
    }
    Ramya:cool:

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default Re: how selected radio button of text check with another string of array??

    You have asked about RadioButton.I told u.
    Just incorporate whatever i told in ur code.
    put proper comments.
    Just take a paper and write what u want to do for systematic approach instead of jumping directly to code.
    Ramya:cool:

Similar Threads

  1. Replies: 1
    Last Post: 12-10-2013, 02:04 AM
  2. delete selected string from all the lines in a text file
    By sreelakshmi.459@gmail.com in forum New To Java
    Replies: 3
    Last Post: 09-19-2013, 09:14 AM
  3. Replies: 4
    Last Post: 11-05-2010, 10:43 AM
  4. Radio Button help!
    By javanator in forum New To Java
    Replies: 3
    Last Post: 04-25-2010, 08:01 PM
  5. How to use SWT Radio Button
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •