Results 1 to 2 of 2
  1. #1
    jayant is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default Is this the correct way of running jFrame as a Thread?

    I have a jFrame Form named "MainForm.java" which runs multiple threads. The basic function of these threads are storing values which are passed from the MainForm class. I want to run multiple threads of jFrame and stop the particular one as soon as it has completed it's task. How can I achieve this?

    Is this the correct way of doing this:

    Java Code:
    public class MainFrom extends javax.swing.jFrame implements Runnable {
    
    @Override
    public void run()
      // Start execution of other threads...
    }
    But I see this in the main method of the class:

    Java Code:
    java.awt.EventQueue.invokeLater(new Runnable() {
       public void run() {
          new MainForm().setVisible(true);
       }
    });
    Please help me out.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: Is this the correct way of running jFrame as a Thread?

    Do not try and run Swing components on multiple threads.
    They are intended to run on the single Event Dispatch Thread.

    If you have calculations that you want to run on multiple threads then write separate classes to do this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Made new JFrame Class, not running though
    By beastman3226 in forum NetBeans
    Replies: 3
    Last Post: 12-05-2012, 01:25 PM
  2. Running only one thread at a time.
    By driiper in forum Threads and Synchronization
    Replies: 7
    Last Post: 08-16-2012, 02:30 AM
  3. Stopping a running thread
    By karthikvadapalli in forum New To Java
    Replies: 5
    Last Post: 12-28-2011, 02:43 PM
  4. Is it possible to keep a thread running?
    By Fortu in forum Threads and Synchronization
    Replies: 5
    Last Post: 01-07-2011, 06:36 PM
  5. How to keep a thread running
    By Fortu in forum New To Java
    Replies: 5
    Last Post: 12-31-2010, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •