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 8574391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:27:51+00:00 2026-06-11T19:27:51+00:00

I have an Idea to develop a java Swing application using the MVC pattern.

  • 0

I have an Idea to develop a java Swing application using the MVC pattern. I have described my idea below and please let me know that, is this a correct way of using the MVC pattern for java Swing?

  • this is the view

enter image description here

following methods are used to get and set the name of the above view,

//at top of the view its model and controller is defined as
    Model model = null;
    Controller controller = null;

//constructor
public view(){
   this.model = new Model();
   this.controller = new Controller(this, model);//controller takes view and model as its parameters.
}


public void v_addShowNameButtonsActionListener(ActionListener al){
    btnActionListener.addActionListener(al);
}

public String v_getName(){
    return txtName.getText();// txtName is the name of the text field.
}

public void v_setName(String name){
    txtName.setText(name);
}
  • this is the controller
  /*at the top of the controller define the view and model*/

    View view = null;
    Model model = null;

    /* constructor of the controller*/
    public Constructor(View view, Model model){
      this.view = view;
      this.model = model;
    }   

    class CreateShowNameButtonsActionListener implements ActionListener{
      @Override
      public void actionPerformed(ActionEvent e) {
          Connection con = null;
          try{
              con = ******************** /*get the data base connection*/    
              view.setName(model.m_getName(con));
          }catch(Exception ex){
              ex.printStackTrace();
          }finally{
              con.close();
          }
      }
    }
  • this is the model
Public class Model{
   public String m_getName(Connection con){
      String name;

      name = ******* //do database queries and set get the name form the database

      return name;
   }
}

I have briefly described the way I am going to implement the MVC pattern in java Swing.

  • 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. Editorial Team
    Editorial Team
    2026-06-11T19:27:52+00:00Added an answer on June 11, 2026 at 7:27 pm

    A change I would make maybe would be to do all database related operations within the model, that is, even managing my own database connections. This will allow the Controller class to be completely independent from the where and the how you get the data.

    All that the Controller needs to know is that it needs to call the Model to get whatever information it needs to eventually pass on to the View.

    As an extra note as well, it is usually a good idea to implement an extra layer between the Controller and the Model, known as a Service layer. This usually comes in handy when you also need to expose certain similar functionality through other means, such as REST. This will allow you to write all your queries in the Model layer, then, any extra customization will be done within the Service layer. This will allow the Controller and REST API to deliver the same functionality without either cluttering the Model layer or else have duplicate code in the Controller and REST API.

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

Sidebar

Related Questions

i wanted to develop a whiteboard application..i know the basics of java..but have no
I need to develop the HTTPS application using Flex and Java. But i have
I have a project idea for my college project to develop an android application
Anyone have idea how to pass value from iPhone application to the REST-Webservice using
I have made the decision to use monotouch to develop an application that browses
I have a server (Java) that is running on UNIX. I'm trying to develop
I've been told I have to develop a Spring 2 application (no idea myself
Here is the idea I would like to develop. I need to have an
I have idea to write errors from my application to the Windows Event Viewer
I have an idea for a functional programming language design that makes heavy use

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.