Results 1 to 12 of 12
  1. #1
    mandragora is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default Double click radio button

    I did some search but didn't find any answers. I'm pretty sure I'm missing something simple. Two panels, one with radio buttons and the other with JButtons. What didn't I do in ActionListener? Why do I have to click radio button twice to get the effect I need (display the letters, one per button...)

    Java Code:
    jrb3letters.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
    	jpComponents.removeAll();
    	randomNumber = (int) ((Math.random() * 100) % 14); // we got 15 words in each array
    	i = randomNumber;
    	jpComponents.add(button1);
            jpComponents.add(button2);
            jpComponents.add(button3);
    	button1 = new JButton(Character.toString(words3[i][0]));
    	button2 = new JButton(Character.toString(words3[i][1]));
            button3 = new JButton(Character.toString(words3[i][2]));
            jpComponents.revalidate();
          }
        })
    I'll appreciate some help

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,335
    Rep Power
    25

    Default

    Why do I have to click radio button twice to get the effect I need
    Can you explain what your code in the listener is doing.
    You add some buttons.
    then you create some new buttons. The new buttons don't have listeners added.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    mandragora is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    Well, it's not finished. I'll do the JButtons listeners when I get rid of the radiobuttons problem.
    What it's supposed to do, when I click radio button no 3 (this code is the listener for it) it clears the panel of all previews components, and sets up 3 new JButtons. That part works, but JButtons do not display what they are supposed to (Each JButton is to display a letter on it taken from an array of chars, words3) until I click that radio button one more time


    Edit
    Quote Originally Posted by Eranga View Post
    You are doing completely wrong thing there. Better to read more about radio buttons first of all.

    Read this article too
    I will, thanks

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It seems that this would be a lot simpler, easier, and foolproof if you used a CardLayout rather than clear a JComponent and relay it out each time a radiobutton has been pressed.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    It seems that this would be a lot simpler, easier, and foolproof if you used a CardLayout rather than clear a JComponent and relay it out each time a radiobutton has been pressed.
    Yep, mandragora has to think about layouts in his code. CardLayout is the best.

  7. #7
    mandragora is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    I'd like to thank Norm who actually helped me with his question. That was what I needed. Thanks, man.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Nevermind.
    Last edited by Fubarable; 11-09-2008 at 04:21 AM.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If you have solved the question please mark the thread as solved. It's really helpful to all other members.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by goldin026wow View Post
    I just can't believe the loveliness of loving you. I just can't believe the one to love this feeling, too. I now know how sweet a kiss could be. Like the summer sunshine, Your sweetness over me. ---------------------------------------------------------------------Hope this helps and wish you will like it. By the way, we are a professional wow gold online store have been created for many years, we supply cheap wow gold for local customers. You may buy cheapest gold for wow on our website. We provide the cheapest world of warcraft gold all the wow servers and the first class service to our loyal and reliable customers. We have available stock of wow power leveling on most of the servers, so that we can do a really instant way of delivery.
    Stop spamming here. You may ban in the forum.

  11. #11
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Stop spamming here. You may ban in the forum.
    I suggest to ban him ;)

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Disable Radio button
    By AJG in forum New To Java
    Replies: 3
    Last Post: 05-10-2011, 11:09 AM
  2. Executing a jar double-click style in Linux
    By goodwillwins in forum AWT / Swing
    Replies: 24
    Last Post: 03-19-2011, 04:56 AM
  3. How to use SWT Radio Button
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-25-2008, 02:25 PM
  4. Reacting Radio button event
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 07:46 PM
  5. Radio button values are not lose
    By chockalingam in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-03-2007, 08:14 AM

Posting Permissions

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