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

    Default Interrupt thread by pressing Enter Key!

    Hi all,

    I'm writing a program has a thread beside the main . I want to let the thread asks me to enter a message and it should then be displayed infinitely.
    If I press the Enter again ,it should ask me to enter a new message to show it consistently.

    How I can use the Enter key to interrupt the thread?

    Any tips!

    Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: Interrupt thread by pressing Enter Key!

    You set a boolean when you press the button and check that boolean in the thread.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Interrupt thread by pressing Enter Key!

    And you'll need to understand this Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Of course, that's only if you have a Swing GUI. Or is this a command line application?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    nadaa is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: Interrupt thread by pressing Enter Key!

    Quote Originally Posted by DarrylBurke View Post
    And you'll need to understand this Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Of course, that's only if you have a Swing GUI. Or is this a command line application?

    db
    Thanks a lot Darry!..it's a command Line . I have solved it..using BufferedReader & readLine method ,after pressing "Enter" the received message is "" .

    Regards,
    Last edited by nadaa; 09-19-2013 at 06:33 PM.

Similar Threads

  1. Interrupt Thread
    By TyCox94 in forum New To Java
    Replies: 9
    Last Post: 09-28-2011, 04:13 AM
  2. interrupt to thread
    By naik_amit in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-26-2010, 07:04 AM
  3. interrupt sleeping thread by mouse action
    By BigBear in forum AWT / Swing
    Replies: 5
    Last Post: 08-12-2010, 10:10 PM
  4. interrupt a jdbc connection thread
    By ko_aung in forum Threads and Synchronization
    Replies: 5
    Last Post: 04-12-2010, 08:04 PM
  5. Replies: 2
    Last Post: 04-12-2009, 10:39 AM

Tags for this Thread

Posting Permissions

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