0

What is the best way to design gui in program where user clicking on button start different jframes responsible for gathering info for object creation? To be consistent with OOP principles?

For example user see a MainFrame at start up with list of objects and information about objects. In a case when user need add new object he must click create new object button. Clicking the button starts another jframe with fields required to create object(Building). But this object is comlex and hold another objects in it - Box(to add Box you click addBoxButton and new frame arising with fields for creating Box).
Box containing another object - Commutator. Again to create Commutator user press another button give rise for new frame creating commutator with user data typed in frame. Then i need to put Commutator in Box and Box than in Building.

Now - I experience some difficulties with information exchange betwee frame classes. For example how should I transfer information gathered from one jframe to another if one of these frames created during runtime?

My question is - Is my GUI an example of bad designed GUI? Maybe its better to put all the gui in one class extending JFrame?

kleopatra
  • 51,061
  • 28
  • 99
  • 211

2 Answers2

1

The typical approach of GUI design is using MVC (Model-View-Controller) pattern where model is responsible on data storage and manipulation, view shows the data and controller connects between these too. There are a lot of tutorials that explain this pattern in depth. Read some of them. I believe that you will find answer to your question.

Generally, data should be into model and view is responsible on as many JFrames as you want.

AlexR
  • 114,158
  • 16
  • 130
  • 208
1
  1. Never mixup the GUIs in this way...

  2. Swing itself is based on MVC principles, that's why it's is called PLAF (Pluggable Look and Feel). While keeping the same model we can change the View.

  3. Try creating your Program keeping the MVC principle in mind.

    MODEL - Deals with Business Logic and Data

    VIEW - Representation of the Output

    CONTROLLER - On which the action is done.

  4. Create separate packages for Model and View.

    Eg:

    com.app.view;     // This stores all of your GUI stuffs
    
    com.app.mode;     // This stores your Business Logic and the Data
    
Arjan
  • 22,808
  • 11
  • 61
  • 71
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75