aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes stuck trying to swap values in JButtons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "stuck trying to swap values in JButtons" Watch "stuck trying to swap values in JButtons" New topic
Author

stuck trying to swap values in JButtons

Logan Wilson
Greenhorn

Joined: Sep 21, 2012
Posts: 17
First I have to start out by saying, you all have been really helpful in your posts that have gotten me unstuck with java problems in the past. I'm hoping ya'll might be able to nudge me in the right direction again. I'm trying to make a GUI frame, that contains a radiobutton group and a jlabel button panel. You can move the labels around by clicking on the radio button to select your starting point and then click on one of the buttons to change the locations. I got it to work without using the GUI, but now that I'm using it, I can't get the values to pass. Any ideas? I know it has to be something simple that I'm overlooking.

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
You haven't added any ActionListeners to your radio buttons or buttons so when you click on them nothing will happen.
Logan Wilson
Greenhorn

Joined: Sep 21, 2012
Posts: 17
Tony Docherty wrote:You haven't added any ActionListeners to your radio buttons or buttons so when you click on them nothing will happen.


I attempted to adding them with my rdoBut and teamBut calls, but Eclipse kept throwing warnings at me and would not let me implement them. Maybe it's because I was trying to pass the radioButton and an index with it?
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
Can you show the code you were trying to use
Logan Wilson
Greenhorn

Joined: Sep 21, 2012
Posts: 17
Tony Docherty wrote:Can you show the code you were trying to use





My classmate advised I should use a set text on the separate string names to repopulate the buttons with switches, and IT will automatically refresh the buttons.
(do the work in a method off to the set.) But, I'm not figuring that part out...I'm hung up somewhere.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5


checkHdlr is a class so you can't use it as reference, that's why Eclipse shows error (not warning, as you wrote). If you want to add your listener to each button, do:


Furthermore, this:

will never evaluate to true (even if the logic is ok, you are comparing two objects with ==, that's not a good idea). Instead, if you want action to be executed when you select radio button, you can write:


Edit:
teamBut is a JButton in your code, so I'm not sure what you want to do here:

Did you check the API to see the signature of getText()? That method has no arguments.


The quieter you are, the more you are able to hear.
Logan Wilson
Greenhorn

Joined: Sep 21, 2012
Posts: 17
Ok, I've worked on it a bit more, but I'm still having trouble wrapping my head around how to make the elements in the buttons shift. For instance, if I click on radio button 1, then click on 8, the text in button 1 should move to button 8, and the other elements shift up. Any more suggestions? I really feel like I'm nearly there, but I've put myself in a rut.



Thanks for all the pointers and help!!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
You need to to sit down with a pen and paper and write out in words exactly what you are trying to achieve and how you can achieve it. Only when you have a coherent list of steps to take to fulfill your requirements should you attempt to put this in code.
 
 
subject: stuck trying to swap values in JButtons