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 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

I really hope you can help out here. I'm creating a theme for a
Hope someone can help me out with this problem I am having. I just
Quick question hopefully someone can help out here. I'm trying to copy and paste
Hopefully somebody can help me out here. I'm working within an embedded ActionScript2 and
Can any trig or GPS experts help me out here? I'm trying to create
I am out of ideas here, so I'm hoping someone can help. Here is
Simple problem, though apparently not a simple solution. Example here: http://myhideout.eu/new/ Basically the site
Anyone that can help me out will be very much appreciated. I seem to
Perhaps someone can help me out with this one: I'm using a basic search
I am hoping someone can help me out with a quick question I have

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.