Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35846
| From | Nigel Wade <nmw@local.domain> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Interrupt code while running (from Form) |
| Date | 2016-10-20 10:33 +0100 |
| Message-ID | <e6rhbjFjnr9U1@mid.individual.net> (permalink) |
| References | <6628a02c-9c5a-4cdc-8113-fcf13c972ea4@googlegroups.com> |
On 20/10/16 09:44, jkl wrote: > Hi > > Sorry for pretty basic question - I'm relearning. > > I'm learning Java again after several years and running Netbeans. I have a simple little form which I'm using to report the output of > prime numbers starting from an integer entered by the user, then the system counts up to another user defined number listing all the prime numbers in between. Pretty simple stuff. > > ... The trouble is, even running in Netbeans, the only way to interrupt it while running is to go outside the form and use the Stop button in Netbeans IDE. I have put a stop button on the form but however many times I click it while the code's running - it's being ignored. > > This is all OO stuff so I'm assuming there's no way within the body of the code I can check for the stop button being pressed. > > I'm missing something fundamental - but can't think what. I would guess that you are missing the fact that if you execute any long-running method on the EDT (Event Dispatch Thread) then the UI will not be able process any events. It's not about Java or OO, it's about understanding how Swing threads and events work. I recommend that you read the Java tutorial on Swing: http://docs.oracle.com/javase/tutorial/uiswing/index.html In particular, if you want to run background/concurrent tasks then it's vital that you read the chapter on Concurrency in Swing; http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Interrupt code while running (from Form) jkl <euclidalgorithm@gmail.com> - 2016-10-20 01:44 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-20 10:33 +0100
Re: Interrupt code while running (from Form) Eric Douglas <e.d.programmer@gmail.com> - 2016-10-20 05:27 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-20 16:01 +0100
Re: Interrupt code while running (from Form) Eric Douglas <e.d.programmer@gmail.com> - 2016-10-20 08:47 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-20 17:49 +0100
Re: Interrupt code while running (from Form) Eric Douglas <e.d.programmer@gmail.com> - 2016-10-20 10:17 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-21 15:38 +0100
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-21 16:38 +0100
Re: Interrupt code while running (from Form) lewbloch@gmail.com - 2016-10-22 16:18 -0700
csiph-web