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.
Related
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
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.
My program is supposed to get information about a person (first and last names, address, phone) so that it can add the person into an address book.
I made a JLabel which gives instructions on what to enter right below. Below the JLabel is a JTextField which has an ActionListener listening to what is being entered. My method has about 8 ActionListener's with 8 actionPerformed methods. I am running into trouble it is not working. I can't figure out any other way.
Best to create a form, perhaps with GridBagLayout or MigLayout that holds displays JLabel/JTextField pairs, so that the user can enter all the data on a single simple form, much like most software you use.
If you absolutely must use a single JTextField, then you should use a single ActionListener, but change how it responds based on the state of the GUI. That is, perhaps use an int counter variable, that you increment each time data is entered, and base what the listener does with the data based on the value held by the counter.
You can create an instance of the listener and reuse it across the class, like:
...
OnChangeListener listener = new OnChangeListener() {
//All the code here
};
...
textField1.addOnChangeListener(listener);
textField2.addOnChangeListener(listener);
textField3.addOnChangeListener(listener);
...
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 have a Swing Application with a JTextField that the user is Supposed to Input ID Numbers. The ID Numbers are Stored in a database. During Inquiry from the DB the End user is again required to Input the ID Number so as to Query the DB. I need suggestions as to what to do so that when the user Inputs the First Digits of the ID Number, Guesses appear below the JtextField for the User to Choose from. Is this Possible with Swing and what Is the Best way to Implement it?
http://www.orbital-computer.de/JComboBox/ Maybe this helps. I know I shouldn't post just a link. But I cannot write everything explained there again here.
Try AutoCompleteDecorator in swingx. Check this post.
still not sure,
you can to use AutoCompleted JComboBox / JTextField (AFAIK ther no issues with Document, Focus, Caret and Selection/HightLighter)
(and to combine with a.m. point) to use filtering in JTable (with one Column and/or without JTableHeader) placed in the undecorated JDialog or JWindow(undecorated by default) in case that you want to display popup window with long list of sentences in the scrollabel contents, that could be clickable
use Swing Timer (5 -10 seconds for autohide for popup window)
share (use the same) model for JTable and AutoCompleted JComboBox / JTextField based on Vector or ArrayList,
to check focus lifecycle (nothing better aroung) for popup window as Java Calendar by Kai Toedter (download codesource)
You should write a PickList class which must contain a SQL Query select * from dbtableName where empId %getUserInput()%;