Forums Register Login

Showing a series of records

+Pie Number of slices to send: Send
Hi,
I am trying to allow the user to select a number of items in a JTree and then have each one displayed in a form one at a time. I have my form class and a display class through which I am trying to pass the form each record. However at the moment all the records are shown on the form at the same time with each one being overwritten by the next. Can anyone see a way to make the form display the new record only when the previous has been submitted by the user?
Display Class

Thanks
+Pie Number of slices to send: Send
Looks like you'll have to do something like load your Tests/TestCases into lists (ArrayLists maybe) and provide the user with navigation controls: "Next Test", "Previous Test", etc.
It looks like your form only shows one step at a time, in which case you need navigation at that level: "Next Step", etc.
So you load the list(s) in your for loops, display the first test/step, and then wait patiently for the user to press something.
+Pie Number of slices to send: Send
I think I am starting to get there. The only problem I am having at the moment is how do i get the loop to wait? I am looking at threads at the moment but I haven't used these before and don't want to make this unnecessarily complex.
Amy
+Pie Number of slices to send: Send
Hi,
I have managed to find a solution by passing the item index around and then incrementing it to show the next test. However i am still interested to know how you would go about waiting for users actions.
Thanks very much
Amy
+Pie Number of slices to send: Send
To wait, you simply do nothing, or rather, you invoke show() on your form and do nothing. Swing has control at this point (or at least that's an easy way to think about it). Swing waits for an event to be handed to it as the result of the user pressing something.
Suppose that the item pressed is a JButton which you have called "Next Test". Swing will cause this button to fire an ActionEvent. "firing" means that the button will broadcast the event to any listeners which have registered with this button for ActionEvents (ActionListeners). Each listener will have its actionPerformed() method invoked with the ActionEvent as an argument.
This is where you get control back. You must build an ActionListener with an actionPerformed() method which, in this case, shows a form with the next test. There are various ways to go about this. I would recommend going through the Swing thread of the Java Tutorial: tutorial.
By the way the particular Swing topic here is "event handling" and you will be learning to write event handlers. This may seem a bit intimidating at first, especially if you have not met up with anonymous classes yet, as this is the most natural way to build an event handler. But it's not really very hard.
Its also worth pointing out that there is a bit of a paradigm shift here. You are used to always having control of the program flow, but in Swing as in all GUI programming, you show the user something and then do nothing - invoking show() gave control back to the system. When something happens, the system will raise an event which causes one of your event handlers to get control. You then take appropriate action and, almost always, relinguish control again by invoking show() on something. This is the rhythm of GUI programming.
A-n-d one more thing: show() is a deprecated method - you're supposed to say setVisible(true). IMHO this is baloney - I use show() because its short and says what it is. So do what you like.
+Pie Number of slices to send: Send
Thanks Steve I think I am starting to understand now
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 789 times.
Similar Threads
Initial display the records in the Table.
How do I know which object is selected?
Serialize many objects to disk..is it possible?
Please help me with a sample code.
Knowning which link was clicked (take 2)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 10:13:10.