I have a program which prompts users to select a choice out of four options (from a group of RadioButtons).
Once the user has made a choice, he/she clicks a button and then receives a message. After closing the window, the user will go back to the first window and make a new selection if desired. What I want is for the radiobuttons to be totally clear.
So far I have implemented a method to actually unselect the radiobuttons and works well (clears the values of the variables), what it doesn't do is to remove the black spot from the previously selected radiobutton. In the other hand this same method works fine with unselecting and unchecking checkboxes.
Any tip to fix this little issue?
Here's my code:
public void clean() {
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);
jRadioButton3.setSelected(false);
jRadioButton4.setSelected(false);
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
}
make them group of buttons and then buttonGroup1.clearSelection();
Related
I have a pretty basic interface of a chromotagram viewer. In the menu I allow the user to reverse the viewer with a JCheckboxMenuItem. Functionally, it does exactly what its supposed to do. My interface allows for multiple chromatograms to be open at once. I will post a few example pictures as I get to my question.
Above I have one tab opened and have yet to reverse the chromatogram.
Above I have clicked the option and it worked.
Here is my issue. If I open another tab and move to it, the option is still checked even though I have yet to click that button. The easy way out would be just to make it a normal button but I just want to know if there is a way that each tabbed could keep track of if its been reversed yet. Would this require multiple instances of the button itself? If anybody has any suggestions, please let me know. Thank you.
if(centralPara.getNumOpen() > 1){
centralPanel = centralList.get(centralPara.getCurrentFrame());
JCheckBoxMenuItem reverseItem = centralPara.getReverseItem();
boolean reversed = centralPanel.getReversed();
reverseItem.setSelected(reversed);
}
in my tab change listener I check to see that we have atleast more than one tab open. if so get the frame we are currently viewing and the top level menu item. Force it be be selected if that the current view frame is selected, or else force it be unselected.
i am fairly experienced at coding in java but i am just learning to build graphical user interfaces in android environment. I have searched alot for the answer to this question but i wonder if im not searching for the right thing?
I want to be able to choose between 2 radio buttons, and if the first of these radio buttons is chosen then a group of 2 more radio buttons should be chosen from. Its hard to explain exactly what i mean so i hope this helps.....
Choice One
1.a choice one a
1.b choice one b
Choice Two
So, if 'choice one' is picked then the user MUST pick from choices 1a OR 1b, whereas if the user picks 'choice two' then the sub options (1a and 1b) are not even available (greyed out i suppose).
I thought i could just nest one RadioGroup inside another, but it doesnt seem to work this way.
If anybody can help me here id be really grateful.
you could create a popup and fill the data on OnCLickListener and then display it.
Have you trying to use show() and hide() for radio button? maybe using a boolean for the parameter show() and hide()
I try to do an image creator program in java (with squares/circles/etc)
I have a few JRadioButtons in a ButtonGroup that symbolizes my program's "mode" (if I draw a circle, something else/if I move the objects).
When I click on different modes, the "mode" changes and I'm able to do what I want.
My problem is when I try to change the mode by double-clicking on an object. I do it in a MouseListener. I'm able to select the object, to change the "mode", but I can't change the selected JRadio Button on my ButtonGroup.
I searched for a while (since the setSelected() is not working). I know that ButtonGroup can have only a button selected at once. How could I deselect the curent one and select the one I need (the first one).
Thank you for any advices.
From the docs:
public void setSelected(boolean b)
Sets the state of the button. Note that this method does not trigger
an actionEvent. Call doClick to perform a programatic action change.
As mentioned here use:
radioBtn.doClick();
I created a small method that allow me to set any radio group button. Very convenient if you don't want to use if for any radio button.
public void setButtonGroup(int rdValue, Enumeration elements ){
while (elements.hasMoreElements()){
AbstractButton button = (AbstractButton)elements.nextElement();
if(Integer.parseInt(button.getActionCommand())==rdValue){
button.setSelected(true);
}
}
}
then
setButtonGroup(yourValue, yourButtonGroup.getElements());
I'm creating a Quiz Software with 40+ questions. Problem is when I click the "Next" Button, I would like to make the current question and answer go and a new set come there in the same frame while also keeping the marks user got for previous question. I can make 40+ Jframes Forms but that would too complicated.
UPDATE: Simply when I click "Next" Button, the question in question box and answers of the radio buttons will change. But this has to be done over and over again, by same button. There's also this previous button that will remove the current question and go back to the last one.
To make things more complicated, each time the there will be different IF selections as the the radio button congaing correct answer also changes.
As I said I can design JFrame forms for each but I'm having a hard taking the marks of each question for one frame (called "Final Result") And there's also this timer that countdown from one hour. I don't think I can do either of these by creating 40+JFrame forms.
You can create just one Frame and on the 'Next' Button Handler, Change Label Text, Check Box Text (Assuming Multiple choice questions)
I'm doing a Matching/Memory Game in JCreator using buttons and if-else statements
When you click the buttons, the image clicked will pop up then if you click the next one, but it's not the same image, then both will close. If you get the correct matching image, they both disable. My problem is the logic of matching it.
What will I do or use to make my program know that two buttons match?
You need to add an ActionListener. Use that link to find out how to detect whether buttons are being pushed and what to do when pushed. To make an image appear, use an icon with the button. When you click, a number changes to a value. If you click another and a number is the same value, then they become disabled. If they are diffrent, then the icon is changed and the number reverts to zero. To disable, use button.setEnable(false);
Use this link for help with button icons/general button help.
Another thing you can do, although it takes more time, is giving each button a numeric value and use RandNum to decide them. If you set it as a constant variable then you can use that to match them