Results 1 to 3 of 3

Thread: Thread Problem

  1. #1
    zhein04 is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default Thread Problem

    Here is the code that i am currently working. The problem is when i start the thread and then the showmessage appears. THe next message wont appear. The thread stops whenever the message appear. is there a way that the message will stack up without closing the first message first?



    public Thread stream = new Thread(){
    // This method is called when the thread runs
    @Override
    public void run() {
    while (true) {
    JOptionPane.showMessageDialog(null, "Number: "+ ctr);
    ctr++;
    try {
    stream.sleep(1000);
    } catch (InterruptedException ex) {
    Logger.getLogger(Main_Menu.class.getName()).log(Le vel.SEVERE, null, ex);
    }
    }
    }
    };// end thread

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    JOptionPane is modal. What that means is that it locks up the AWT thread until the user makes a selection ("ok", "cancel", etc.). If you want an joptionpane equivalent that does not block the AWT thread, you have to write one yourself and you have to be very careful, because swing is not thread safe.

  3. #3
    zhein04 is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    how can i do that?

    when i try creating a Jframe. ang applying the code. the jframes wont stack up it just changes the text inside of it.

Similar Threads

  1. Thread location problem?
    By AMaineJR in forum Threads and Synchronization
    Replies: 1
    Last Post: 10-01-2010, 03:38 AM
  2. Thread problem.
    By Mekonom in forum New To Java
    Replies: 4
    Last Post: 03-16-2010, 04:19 PM
  3. thread problem
    By Harris68 in forum Networking
    Replies: 3
    Last Post: 03-03-2010, 07:53 PM
  4. Problem with a thread
    By dotabyss in forum Threads and Synchronization
    Replies: 3
    Last Post: 02-14-2010, 10:56 PM
  5. Problem using thread +rmi in my homework
    By IbrahimAbbas in forum Threads and Synchronization
    Replies: 10
    Last Post: 04-14-2008, 09:24 PM

Posting Permissions

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