• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

stuck trying to swap values in JButtons

 
Logan Wilson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2969
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't added any ActionListeners to your radio buttons or buttons so when you click on them nothing will happen.
 
Logan Wilson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2969
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the code you were trying to use
 
Logan Wilson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Logan Wilson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2969
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic