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

The Archive Base Latest Questions

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

When writing a graphical interface, using Java, what’s the appropriate way of switching between

  • 0

When writing a graphical interface, using Java, what’s the appropriate way of switching between the different windows of the application, when clicking a button for example? I.E. what are the windows supposed to be, JPanels, JFrames…? And how do all the components ‘see’ the ‘domain controller’ (the class that links the graphical package to the application logic package)?

Any guide or reference would be appreciated.

  • 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-05-23T00:17:11+00:00Added an answer on May 23, 2026 at 12:17 am

    You start your application with your Controller. In the constructor of your controller, you are going to initialize the first GUI you want to open, lets say GUI_A:

    private GUI_A gui_a = null;
    
    Controller() {
        gui_a = new GUI_A(this);
    }
    

    As you might notice, I called the constructor of GUI_A with one parameter: this. this is referencing the instance of the current class, so this is type of Controller. The constructor of GUI_A has to look something like this:

    private Controller controller = null;
    
    GUI_A(Controller ctrl) {
        controller = ctrl;
    }
    

    This is a simple way to get the GUI known to the Controller.

    The next thing you would do is displaying GUI_A:

    gui_a.setVisible(true);
    

    If you now want to handle button-clicks, you would do it like this:

    First, you add the action-performed method to your button. And, as it is best practice in MVC, you don’t want to do logic in your view/GUI. So you also create a corresponding method in your Controller for the action-performed, and call it from your GUI:

    // Controller
    GUI_A_button1_actionPerformed(ActionEvent evt) {
        // Add your button logic here
    }
    
    // GUI_A
    button1_actionPerformed(ActionEvent evt) {
        controller.GUI_A_button1_actionPerformed(evt);
    }
    

    Usually you don’t need to pass the ActionEvent-var to the Controller, as you will not need it often. More often you would read a text out of a TextField and pass it on to your Controller:

    // Controller
    GUI_A_button1_actionPerformed(String text) {
        // Add logic for the text here
    }
    
    // GUI_A
    button1_actionPerformed(ActionEvent evt) {
        controller.GUI_A_button1_actionPerformed(textField1.getText());
    }
    

    If you now want to access some fields on your GUI_A from the Controller, be sure not to mark the fields as public in your GUI, but to create public methods which handle how to display the values.

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

Sidebar

Related Questions

I am writing a client-side Swing application (graphical font designer) on Java 5 .
Writing my first Linq application, and I'm trying to find the best way to
I'm writing a graphical user interface to plot data on a xy-axis. It's written
I'm looking into writing a wxWidget that displays a graphical node network, and therefore
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I'm writing an interface that features a large (~50000px width) canvas-type area that is
I'm writing a C# (ActiveX) plugin for an application that uses SetCompatibleTextRenderingDefault(true) (forces .net
I'm writing a graphical URI handler for git:// links with bash and zenity, and
I'm writing a GTK+ application. At the end of the program's running, it opens
I'm writing a s:ItemRenderer to render some simple graphical components in my app. Each

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.