• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Classes

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am producing a very large program and am concerned about the size of my classes. In particular my Program involves user-interfaces and this after certain buttons are pressed a new user interface is created providing the user with more options. Should these different user interfaces be kept in different classes and then invoked within each other when certain things happen? At the moment they are all within one class which is becomming very big and I am concerned that this may also increase memoey usage and make the program slower??? If the user interfaces could be separated into different classes could you please provide an example of this happening, ie, how would you invoke one class from another?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should these different user interfaces be kept in different classes and then invoked within each other when certain things happen?
That might be a good idea, as it's often much easier to understand and maintain a few interworking smaller, well designed components with clear and limited responsibilities, than one big messy component that is trying to do everything.
 
Naf Rash
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, But could you possibly provide an example of how i would invoke a method for example from another class?
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Naf Rash:
Okay, But could you possibly provide an example of how i would invoke a method for example from another class?


This is a very simple example

To call a method in another class, you first create an instance of that class, then you can call it's methods.
Search on google for infomation on the MVC pattern. I personally think this pattern should always be used in GUI design.
HTH
Nigel
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a class file which constructs a page with several buttons on it. The page will redirect to a new page depending on which button is selected.
My Button choices are "Save, Done, Cancel or Preview".
Here is the post method from this class file:

If the Preview button is hit, the following method is called from the post method:

The redirect causes another page to be drawn, the preview page, which has it's own separate class file.
Not sure if this is the kind of info you were looking for, hope it helps.
[ February 24, 2004: Message edited by: Kim Kantola ]
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should have mentioned that my post refers to servlet code,
Nigel's looks a bit more easy to follow if you are not working on servlet code.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naf Rash - you might scroll down to the UML and OO forum where we talk about design a lot. Look for existing messages about MVC or Model View Controller. MVC ideas apply well to Swing programs and have been adapted to web applications, too. They may give you some good ideas about how to structure a large app with many windows or pages. See ya there!
(I will repeat tho, look for existing messages first. We've talked about MVC quite a few times so there should be something good there.)
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not well versed with MVC, but I thought I'd add my two cents. When I design a GUI in Java, I generally have several classes, even for the simplest program.
First, I extend Frame or JFrame, depending on whether I'm using AWT or Swing.

Then I also extend Panel or JPanel:

Typically the constructor of MyFrame creates an instance of MyPanel for its use and the MyPanel constructor creates the buttons and other controls necessary for display:

I have found that this scheme works well for me. For one thing, it is simple to reuse MyPanel in an applet by creating another class that extends Applet then creates an instance of MyPanel. This makes it easy to port a desktop application to an applet on the Web.
Also, it doesn't take much effort to add more complex elements to the program. You could create two more classes that extend JFrame and JPanel respectively. This new frame can add an instance of the new panel class. Then MyFrame can create an instance of this second frame and open it.
I don't know if this will work well for the project you are working on, but I thought I'd at least suggest it. Perhaps some of it will help give you ideas about what can work for you.
Keep Coding! (TM)
Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic