• 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

Design question involving GUI and classes.

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, you have a program where you first sign in, then you have a window (errm, frame ) open, in the frame there's a drop-down menu, each item on the menu opens a new frame, similar to the "tools" menu in your web-browser, as an example.

Now does the "sign-in" screen and each item on the menue get programmed in a separate class, where clicking on an item creates a new object of that class and has the code to display it in its constructor? Or is that not how you write a multiple-window program?
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add an ItemListener to the JComboBox and create the new JFrames in the event handler.

[ October 24, 2007: Message edited by: Jan van Mansum ]

[ October 24, 2007: Message edited by: Jan van Mansum ]
[ October 24, 2007: Message edited by: Jan van Mansum ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a common practice to have a Controller object that orchestrates the goings on between windows and the business/data side of an application. One common pattern is called "Model View Controller". Googling for that will find some technical and rather advanced discussions, so let's try to approach it more gently.

At a high level it might look like:

The Model here is some Plain Old Java Object that maybe checks the userid & password against a database. The Controller has the logic to decide what to do when authenticate succeeds or fails.

Showing a window calling the Controller skips over a lot of details - buttons and listeners and such. It sounds like you're getting comfortable with those things. Just make a button event handler that calls the Controller.

Other menu options should do much the same thing - just tell the Controller that something happened. I like a description of the controller "interpreting user gestures", messages like "The user hit this button" or at a slightly higher level "The user wants to close the application now"

Does that kind of thing make sense? Scroll down to the OO, UML, etc. forum for more detailed discussions of designs like this.
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the answers...

It's just when you tackle that first small project where design actually matters, it's scary how there are a million ways to do something right, and a billion ways to do it wrong, and you gotta pick one.
 
Oh. Hi guys! Look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic