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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:36:05+00:00 2026-05-16T05:36:05+00:00

I’m building a Java GUI for some code, and I’m not quite sure about

  • 0

I’m building a Java GUI for some code, and I’m not quite sure about some design aspects.

As some background – The GUI will be used only for one stream of activity

  • The user loads a file, the file appears on the screen and the user is shown the effects of mathematical transformation 1, transformation 2, and transformation 3 each time after pressing a button to indicate a yes/no answer.

What I was wondering was – is it ok design to somewhat hard code the GUI code so that after the file is loaded, the events associated with the buttons change from connecting with transformation(s) 1 to 2 to 3?

The functionality for these transformations is implemented in another Java file, and I was wondering how I separation/communication between the two would work; or if I should just go ahead and use one file to cover both the mathematical functionality to be performed with the GUI items.

Please feel free to ask any questions that you think will help you answer this question.

  • 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-16T05:36:05+00:00Added an answer on May 16, 2026 at 5:36 am

    Do some research on the Model-View-Controller paradigm; it’s probably best suited for what you’re trying to do.

    In your current setup, the code you have written is the model. It contains all of the ‘business logic’ for your application. What you need to write is the front end, the View and the Controller. The Controller acts as the intermediary between the View and the Model; when you click on a button (a view element) the associated button handler (the controller) will delegate to the Model by calling some method. For instance

    public class View extends JPanel implements ActionListener {
    
      JButton transform = new JButton("Transform1");
      Model m;
      public View(Model m) {
           super();
           this.m = m;
           transform.setActionListener(this);
           // lay out the GUI
           setLayout(...);
           add(// whatever view you need to visualize the data);
           add(transform);
      }
    
      /**
       Make sure all of the GUI elements are correct */
      public void update() {
        State transformState = m.getTransformState();
        transform.setText(transformState.getNextStateDescription());
    
        // Draw the state of the file they loaded in, probably to another JPanel
      }
    
      public void actionPerformed(ActionEvent e) {
        m.transform();
      }
    
    }
    

    In small examples it’s probably fine to have the View and Controller intermingled like this (the view is handling the button presses in this example).

    As far as communication among the two, what I would recommend is that you make your Model extends Observable

    public class Model extends Observable {
        public void transform() {
    
           // Do the transformation
    
           // notify the view
           setChanged();
           notifyObservers();
        }
    }
    

    and make the View implement Observer

    public class View implements ActionListener, Observer {
    
        public View(Model m) {
                // snip
                m.addObserver(this);
        }
    
        public void     update(Observable o, Object arg) {
            // Delegate to previously defined method
            update();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
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.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.