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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:39:26+00:00 2026-06-13T11:39:26+00:00

I am new to Swing so this might seem like a very naive question.

  • 0

I am new to Swing so this might seem like a very naive question.

I have a JFrame which displays an initial statement and two radiobuttons. RadioButton1 is Accept and RadioButton2 is Reject. If the user chooses Accept, the program proceeds. So I have created an ActionListener for Accept so that the rest of my code is within this ActionListener. However, as soon as the user presses Accept, the GUI freezes. Pressing Reject just exists out of the program.

    public void game() throws Exception
    {
        jTextArea1.setLineWrap(true);
        jTextArea1.setWrapStyleWord(true);
        jTextArea1.setText("Please choose Accept or Reject");


        jRadioButton1.setVisible(true);
        jRadioButton2.setVisible(true);

            jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {

              jRadioButton1.setVisible(false);
              jRadioButton2.setVisible(false);
              repaint();
             //more code
           });
    }

After this I make connections to the server which works fine since when I use System.out.println(), all the outputs are fine, just the GUI is frozen.

Is there a better way to continue when the user presses Accept?

  • 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-13T11:39:27+00:00Added an answer on June 13, 2026 at 11:39 am

    You can look at using the SwingWorker class.

    Basically, Java Swing applications are single threaded and if there are any process intensive tasks which you perform, the control transfers to that section of code and the UI hangs, waiting for control to be handed back.

    Edit: You can also look into the SwingUtilities class.

    Edit: Basic info on using the SwingWorker class:

    You can create a new class which extends SwingWorker and implement the public String doInBackground() {
    /*Do Stuff here*/
    }
    method. And in your ActionListener event, create an instance of the SwingWorker and call the swingWorkerObject.execute() method to start the doInBackground method execution.

    More details here: http://docs.oracle.com/javase/6/docs/api/javax/swing/SwingWorker.html

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

Sidebar

Related Questions

I am quiet new to Swing. I have a JTable in which images are
I am new to Swing. There is a silly question that I have. It
I am new to Java Swing I want to develop an POS application which
I'm new to Java Swing applications and I'd like to port an old WindowsForm
i am new to netbeans ide , i have a swing desktop application and
New to PHP and MySQL, have heard amazing things about this website from Leo
I'm trying to build a new java swing component, I realise that I might
Why doesn't this Swing-based program terminate when its window is closed? import javax.swing.JFrame; import
I know this questions might seem a little odd, but I want to make
I first asked this question, which I figured out how the EDT works and

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.