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

  • Home
  • SEARCH
  • 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 593725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:52:35+00:00 2026-05-13T15:52:35+00:00

Can you help me out here? A really simple problem but I just can’t

  • 0

Can you help me out here? A really simple problem but I just can’t get what the solution is!

I am coding a listener application that runs on its own thread & listens on a ServerSocket for incoming connections.

When a connection arrives, a new ‘Message’ object is created on a new thread and passed the incoming text data “messageData“. This object should then display the text to the user in a popup window.

In Listener.java:

javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {

        Message.display(messageData);

    }
});

Then, in Message.java:

public Message {

    public static void display(String data) {

        Message message = new Message(data);

        message.initGUI();

    }

    String messageData;

    GUI gui;

    public Message(String data) {

        messageData = data;

        gui = new GUI();

    }

    public void initGUI() {

        gui.init();

        // add listeners
        gui.addOKListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                // close GUI
                javax.swing.SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        gui.close();
                    }
                });

                gui = null;

            }
        });

    }

    public class GUI {
        do GUI stuff 
        ... initialise gui
        ... add components
        ... setVisible=true
    }
}

The idea is that the inner class GUI is the ‘View’ and that the Message object is the model and controller combined.

Each Message object initially creates itself via the static Message.display() method. This means that there can be unlimited Message objects all existing independently and the Listener doesn’t have to worry about managing them.

Great. However I now have a problem.

When the user clicks ‘OK’ on the GUI, I want (a) the GUI to be deleted/hidden, AND (b) the Message object to be deleted from memory.

How can I do (a) and (b)? I can do (a) by
gui=null in gui.addOKListener() (see above) but I can’t do (b) because I don’t have a reference to the Message object.

I have tried to define addOKListener() in Message.display() but this doesn’t work because I have to make the message object that I create final, therefore message=null is illegal.

A really simple problem- I am guessing the solution is also simple. This is very frustrating..

Thanks alot

Will

  • 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-13T15:52:35+00:00Added an answer on May 13, 2026 at 3:52 pm

    If all you want to do is to display a dialog with a short test message to the user it should be a lot easier if you used JOptionPane and one of the static factory methods in there.

    Have a look at the tutorial

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

Sidebar

Related Questions

Can i get the source code for a WAMP stack installer somewhere? Any help
I need to solve the following question which i can't get to work by
If all tables I want to delete from have the column gamer_id can i
i have a input tag which is non editable, but some times i need
I'm working on a project in C# w/ XNA, and I want to reorganize
I have found this example on StackOverflow: var people = new List<Person> { new
I'm in the process of porting some code from Linux to Mac OS X.
I want to use a temp directory that will be unique to this build.
Every time that I want to do a Layout, I'm getting a black layout
I'm trying to build a C++ extension for python using swig. I've followed the

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.