Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:17:19+00:00 2026-05-11T06:17:19+00:00

I’m writing a Swing application, and further to my previous question , have settled

  • 0

I’m writing a Swing application, and further to my previous question, have settled on using the Model-View-Presenter pattern to separate the user interface from the business logic.

When my application starts up, it executes the following code:

Model model = new BasicModel(); Presenter presenter = new Presenter(model); View view = new SwingView(presenter); presenter.setView(view);  presenter.init(); 

which creates the user interface. Events are generated by the View, and delegated to the Presenter. The Presenter then manipulates the Model and updates the View accordingly.

In order to handle some events, I need to obtain further information from the user. In the case of these events, I believe it is appropriate for the Swing view to spawn a new JDialog window.

One line of thinking makes me feel this might be appropriate code in the orignal Presenter:

public void handlePreferences() {     Preferences prefs = view.getPreferences();     model.setPreferences(prefs); } 

That is, the contents of each JDialog should represent a distinct object that should be retrieved from the View and updated in the Model. However, this leaves the question: do I create a new Model to represent the Preferences object and a new Presenter for event handling in that JDialog?

It seems to me that creating a new Presenter and Model internal to the original View forces me to do a lot of work that would be harder to port if I wanted to change the UI to use JSF, for example.

Please feel free to add comments for clarification.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:17:20+00:00Added an answer on May 11, 2026 at 6:17 am

    Although it is not uncommon to have ‘nested’ design patterns it is not necessary in your case. Drawing on the other answers:

    Model
     – Contains all the real data, variables, objects
     – knows how to set its stored data values to the new values
     – responds to orders (method calls)
     – has method setPreferences(value1,value2,value3…);

    View
     – is the IO for the application, just output and input
     – it can only work on its self, on its state
     – it maintains local variables and objects, eg. it has JButtons, JMenus, int counters …
     – it is knows how to inform the Presenter of State Change
     – its state is visible to the Presenter, or revealed by method call
     – responds to orders (method calls)
     – knows how to get preferences from the user
     – has method askForPrefs();
     – has method getPrefState();

    Presenter
     – Responds to state changes
     – does all the deciding, it tells the other objects what to do (not how to do it)
     – knows when preferences are needed
     – knows where to get new preferences and where to put them
     – has method newPrefsAvailable();

    … to obtain further information from the user. In the case of these events, I believe it is appropriate for the Swing view to spawn a new JDialog window.

    Presenter – checks the Model, determines new preferences are required
    Presenter – this.myView.askForPrefs(); //tells view to ask user for pref values
    View.askForPrefs – pops up a JDialog box, retVals stored in the view as a state change
    View – this.myPresenter.newPrefsAvailable();
    Presenter – responds with this.myModel.setPreferences (this.myView.getPrefState());
    Model.setPreferences – changes the stored values to View.getPrefState()
    Presenter – checks the Model – determines preferences are good
    Presenter – continues on

    The JDialog is treated as just an extension of the View,it is a member of the View just like a JButton would be. The model has the authoritative actual preference values, and the view has local variables that represent the state of the JDialog.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.