Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Modifying a complicated object with dialog boxes

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Modifying a complicated object with dialog boxes

    Hello all,

    I'm looking for some advice. Basically I have a GUI that modifies a fairly complicated object. By this I mean that the object can have nested dialog boxes that modify nested elements of the object. ie:

    Object A contains
    Object B
    Object C

    If we want to modify Object C, a new dialog box opens.

    Object C contains
    Object Y
    Object Z

    If we want to modify Object Z a new dialog box opens for editing etc...

    What I'm trying to determine is the best method for editing these objects. I see myself as having 3 options:

    1. I can directly modify the reference to Object A, Object C, Object Z etc...however if the user cancels the editing dialog box it may be a pain to rollback changes.
    2. I can create an object that stores all changes made and once the user clicks 'ok', I copy over each change to the real object...but that seems like a lot of work and can get cumbersome if I have a lot of different types of objects
    3. I simply change the object reference to reference the modified dialog object...but that seems a little dangerous since other objects may still reference the stale object.

    What does everyone think the best course of action would be?

    Thanks in advance!


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Modifying a complicated object with dialog boxes

    I will prefer 2 approach , because it seems to be feasible then other 2.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: Modifying a complicated object with dialog boxes

    To be honest, it doesn't really matter what we think. Which way makes more sense to you? Do that one and go from there.

    Or better yet, try doing it in different ways and then use the actual code to determine which is better, however you define that.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: Modifying a complicated object with dialog boxes

    I have a curiosity question: why are you using dialog boxes instead of a form? It seems a form would solve all of your problems.

    If you had to do it with dialog boxes for whatever reason, I would suggest adding to your Objects to make it easier to update data. For instance, lets say you went with #2. I would create a method in your Object A that accepts an Object A and sets the data accordingly. That may be easier to code and more readable than trying to accomplish everything in your main (or where ever). If you went with #1, you could make several methods for each setting variable where it has a 'previous' variable that contains the Object's last value for that variable. Then you could create some methods to set the variables based on the saved previous values. Then you could create a 'rollback' method in Object A that would simply run through and call all of those methods.

    #2 is much more elegant and easier than #1, but they are both possible. I would not advise #3. Like you said, problems could occur.

    Overall, go with a form if you are not restricted to dialog boxes. If you need help making a form, I can step you through it.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,301
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Modifying a complicated object with dialog boxes

    As KevinWorkman correctly pointed out that you must do what makes more sense to you, I will point out an alternative:
    Basically I have a GUI that modifies a fairly complicated object. By this I mean that the object can have nested dialog boxes that modify nested elements of the object
    Seems like your data and GUI are tightly intertwined...I'd recommend separating your model/data away from the GUI to make if follow more of a typical MVC (Model/View/Controller) architecture. Embedding both together can grow into a nightmare, and makes making changes (say for instance taking ausiemcgr's advice to make a form) in the long run much harder. Having the two separated makes accomplishing the above a piece of cake.

  6. #6
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Modifying a complicated object with dialog boxes

    Sorry I don't think I'm familiar with forms...is this a Java object that maybe I'm not familiar with or do you mean using a JFrame? If it's the latter how does it differ from using a dialog box?

    Seems like your data and GUI are tightly intertwined...I'd recommend separating your model/data away from the GUI to make if follow more of a typical MVC (Model/View/Controller) architecture
    I'm keeping all my model data in a controller object. This controller object maintains listeners on the GUI and updates the model appropriately when there are any changes...is this an appropriate way to maintain an MVC architecture?

    Thanks for all your responses!

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,301
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Modifying a complicated object with dialog boxes

    Sorry I don't think I'm familiar with forms...is this a Java object that maybe I'm not familiar with or do you mean using a JFrame? If it's the latter how does it differ from using a dialog box?
    I can't speak for ausiemcgr, but my understanding is they are suggesting a more complex gui than a Dialog, a JFrame containing input of all sorts rather than using successive dialogs that can are cumbersome.

    is this an appropriate way to maintain an MVC architecture?
    The term MVC is extremely broad, and I have seen it 'applied' in all sorts of ways. Its appropriate when the architecture makes the program as flexible and maintainable as possible. Your original question gave me the impression that the model is spread across multiple objects which manage smaller components of the model...and my suggestion was to pull all those out into a single interface/object to give you the flexibility of monitoring/controlling/reverting changes to the model. I will go back and point out KevinWorkman's advice however, whatever makes sense to you. The right way is the way that works.
    Last edited by copeg; January 23rd, 2011 at 10:47 PM.

  8. #8
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: Modifying a complicated object with dialog boxes

    Quote Originally Posted by copeg View Post
    I can't speak for ausiemcgr, but my understanding is they are suggesting a more complex gui than a Dialog, a JFrame containing input of all sorts rather than using successive dialogs that can are cumbersome.
    Ya, I was referring to a GUI that allow multiple inputs of data in one go rather than one by one.

    To give a visual representation of what I mean:
    Dialog: http://download.oracle.com/javase/tu...alog2Metal.png
    Form: http://download.oracle.com/javase/tu...tInputDemo.png
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Saving a file using a dialog box
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 5th, 2010, 04:21 PM
  2. Interating through an ArrayOrderedList and modifying elements within
    By xecure in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 26th, 2010, 10:15 PM
  3. Swing Dialog Boxes --- Have no clue why its not working
    By jap2008 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 18th, 2010, 03:20 PM
  4. how to write an if statement which evaluates 3 dialogue boxes
    By humdinger in forum Loops & Control Statements
    Replies: 6
    Last Post: January 14th, 2010, 12:28 PM
  5. [SOLVED] Help with dialog box
    By 03EVOAWD in forum AWT / Java Swing
    Replies: 5
    Last Post: August 4th, 2009, 11:06 AM