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)
Related
I'm working on a small app for a class. One of the functions I want is when a button is clicked, it adds an object to an ArrayList based on the fields that they filled. When they click they button, I want them to have visual confirmation that the action has been performed. However, just updating a JLabel would cause it to sit there forever after the button was clicked.
I would like the label to start off displaying "".
When the button is clicked, I want it to say "Character Added!"
..for a few seconds. and then switch back to "".
I looked up some questions about label updating using a timer, but most of them have been using it to display a counting down clock, and they usually use a timer start method. I'm confused about if you need a timer stop method to reset the label.
Any pointers?
What I ended up doing is, instead of using a JLabel that updates, I simply made it so when the button is pressed and a character is added to the ArrayList, I called
JOptionPane.showMessageDialogue("Character Added!");
That way instead of a small little JLabel confirming it, they get a very apparent notification that requires them to acknowledge it. Tons more simple than doing the whole Timer thing.
I'm newish to programming so there might be something obvious I don't know of that's a solution to this.
I'm currently writing a program that tests the user on words that they've entered before. When the user is entering words, the screen shows a jtextfield and jtextarea among other things for adding a word and it's definition and a variable is set to the constant NOT_TESTING to remember that that's the screen being displayed. My question is, when I want to switch screens to show the testing screen which has a jlabel displaying the word and a different jtextfield to write the definition of a word, what's the best way to not show the jtextfield and jtextarea from the screen where the user submits a word? (I'm not sure screen is the proper term, but I'm using it anyway.) If I don't make the components instnace variables, then I can't remove them when making a different screen, but it seems ridiculous to make them instance variables and then remove them whenever I switch screens, create new objects when going back to the old screen, and have so many instance variables.
Sorry for the long explanation, basically my question is: what's the best way to not show objects from previous screens when drawing a new screen?
Take a look at CardLayout, which allows multiple JPanels to be shown without the other one showing (basically, it makes the entire window that panel and you can switch between them).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm a student and still learning a lot about Java, but I have a pretty good grasp on the basics. Right now I am trying to figure out a way to recreate a radio button to mesh with the UI design for an application I have been commissioned to build.
The entire application is meant to be designed around the Star Trek LCARS interface (Bold bars, distinct color changes, no check boxes or radio buttons). I need to incorporate radio buttons into the design, but I have been unable to find any resource that will allow me to design a radio button without that distinctive filled/empty circle.
I already have a good idea of how I need to work the design. The selected item will change to a different display color with the mouse click or touchscreen tap. Selecting another item in the same group would deselect the original and select the new option, while trying to select the same item would unselect all choices (Select an undisplayed, "default option").
The problem is pure aesthetics, but it is important to the customer.
Is it possible to create a label (or other component) and have the ActionListener "transfer" the user interaction with the object to a radio button? In other words, the user clicks on the selection label and it fires off the same commands (change item/text color, play sound) and also fires off a command to set a designated radio button to either on or off?
well first of all... Everything is possible..its just a matter of how much time/effort you want to put in.
If I read that right..You have suggested creating a hidden radio button that gets information passed to it. This would work but is probably not the best way to design it.
I would personally just make an integer and call it mostRecentLabel or something to that effect and if you have 4 labels you would just keep track of which label was "turned on" with your mostRecentLabel variable. Then just put a function in that responds whenever a label is clicked to update your mostRecentLabel and this would update the display accordingly
I have been trying to develop swing application which contains jxtreetable in which i do have Jbutton(which is used for navigation to another frame for editing that particular record)
previously i was just showing the window by creating new instance but later i realized that every time it opens new window (so if user clicked it 10 times then there will be 10 different window) so to avoid it i had implemented singleton design pattern which doesn't allow multiple window to opened
but at the same time if click on one edit button and then on another edit button it does refreshes the content within the frame on the first go but not on the second time
Edit Button is Jbutton which has been added to the jxtreetable column.
is that thing happening due to reference is existed already ?how to workaround this?
I do have JButton(which is used for navigation to another frame for
editing that particular record) previously i was just showing the
window by creating new instance but later i realized that every time
it opens new window (so if user clicked it 10 times then there will be
10 different window)
Note: remarks are mine.
There's no need to implement Singleton Pattern here, it is intended to other purposes. You just need to read about Modality: How to Use Modality in Dialogs.
If the JButton is pressed don't show a new JFrame to edit the selected record but use a modal JDialog instead. This way the user won't be able to click the JButton again until this JDialog is closed. Consequently a single instance of the edit window will be shown, what is actually your goal.
I (very miraculously) answered my own question while writing this question , but it was such a find I wanted to share with everyone. I understand these should be true "questions" but it was a monumental find for me. There is a "question" below that can be answered, however.
I created a custom class that extends a JToggleButton. In this class, I remove all default MouseListeners so it will only accept mouse actions when I deem the object ready. The problem I had was manipulating the JToggleButtons ImageIcon (set with setIcon()). If the button was not displayed on screen (not visible due to a JScrollPane) when I told the button to be selected, the ImageIcon would disappear. Similarly, if I modified the ImageIcon while the button was selected, the ImageIcon would also disappear.
It turns out that in my custom MouseListener, I was using getModel.setSelected(true) instead of getModel.setPressed(true). Apparently I don't have a clear understanding of the difference between selected and pressed, but suffice to say this fixed my issue. My "question" would therefore be clarification on these two terms.
To summarize, don't use setSelected() on a button when you mean to use setPressed(). What a pain to track this one down! I sincerely hope this helps someone else. Email is valid but a spam-catcher.
Ok, I found my own answer again, so I thought I'd share and close this question. A button is "selected" when it has a checkbox/radio icon. A button is "pressed" when the button has been pushed. JToggleButtons appear to use both attributes in combination to properly "click and press" the button.
The reason the ImageIcons were disappearing was because I had inadvertently mixed setPressedIcon()/setPressed() and setSelectedIcon()/setSelected(). Because I had confused the terminology and didn't recognize the difference, I was inconsistent in my usage.