• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Showing a series of records

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Steve Lovelace
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve I think I am starting to understand now
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic