The situation is:
I want to use two date values obtained from two jDateChoosers and calculate the number of days between two selected days.
The question is: what should I do that after choosing both dates a calculated value would appear in a label (or Text Field, which one is better?) without any additional submission (in other words, without clicking on any buttons ect.)?
Have an actionListener checking for if both dates have been input when the jDateChoosers close and then have a function such as update() to perform the calculations and update your label
Related
Say a game allows you to choose a number of players, and then asks for each player's name based on that number.
The first user inputs their name in a JTextField, and clicks a JButton (which stores their name in a list).
After the button is clicked, the JPanel erases the user's name from the JTextField so that the second person may enter their name, and so on.
How would I do this? Would I use a loop?
How would I do this? Would I use a loop?
Nope. Using a loop is a construct that you'd use in a linear console-driven programming environment to get repeated input from the user. Instead Swing is an event-driven library, and in this situation you have to think differently since here you'd use state-dependent interaction with the user.
So say you wanted to get 5 records of information from the user, you'd use a counter, and each time the submit button is pressed, you'd get the input from the GUI components, create an object with them add them to whatever collection is holding the information, perhaps an ArrayList or a JTable's model, and then when the maximum number is reached by the counter (the state variable that you'd be monitoring), you'd stop getting input, and perhaps even change the GUI view entirely to reflect this change in state, something that you could use a CardLayout to help with.
I need a help. I am doing a reservation system and my doubt is:
I have 2 JDateChoosers and JTextFields and one JDateChooser is for the start and one is for the end.
For example the user selects a date from the start JDateChooser and after he entered the number of years in the JTextField automatically the end JDateChooser changes the year. The user can't edit the end JDateChooser.
Select the Date from JDateChooser "start".
Enter the number of years in the JTextField.
Automatically the "end" JDateChooser's value changes.
Look into the mediator design pattern.
Basically you will have one object (the mediatory) which will be responsible for coordinating the state between a number of GUI components. So, when one person enters in something in one of the text boxes, that mediator is a listener on the text box, and will set the other GUI component's state accordingly.
So I have a form that I want a User to fill out
it must have the date at the top which are 3 combo boxes for Day, month and year.
then I give them a form which they can partially fill out
So lets say there are 4 rows
each row has a combo box and a field.
Now i've been testing for the past hour nearly to check if one when is null is the other? otherwise it's invalid.
I've tried combo.toString() and then testing if that was null or empty but that didn't work for some reason.
So basically if the combo box has no value, then the field can have no value too, but if one has a value then the other MUST, otherwise the form is invalid.
Please help
I used PrimeFaces LineChart. It works properly when all values are available but if there is no item one of the x-axes values(months). One of the series doesn't have item in the first two month and there is in third month. It shows its label points not properly. Items value for March displayed in March correctly but its label points displayed in february which is wrong. How to handle this issue I couldn't find solution through web.
You have to handle this issue in time you are creating the series. Simply check if the item has all attributes needed or isn't null. Series has to contain only valid data in time they are loaded to LineChart by Primefaces.
So I have two JComboBoxes, and what I am trying to do is be able to compare the value in one, with the value in the second and then figure out the difference or the total. I want to be able to input a time in the first box (let's say 8:00 A.M) and then I want to be able to input 5:00 P.M in the second box, and have it display 9.
Is there a way to do this?
I don't have any working code, just need to be steered in the right direction.
you can add itemListener on both the comboboxes and in those item listeners, check if there is something selected in other combobox...accordingly you can perform your calculations....