• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to stop a method

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I'm trying to stop a method by using a button.

method.stop();

dosen't work.

I'm not sure how to approache this problem.
Do i have to kill the program!

Any advice would be awesome.

cheers
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gregory,

I'm not sure what you are really trying to achieve. Anyway it's not possible to simply "stop" a method from outside the method...

Do you want to stop some background task? To do this you will have to know a little bit about thread programming in Java. If this is what you want you could Google for examples of how to use the class SwingWorker which is designed to execute background tasks in a different thread in Swing based applications.

Marco
 
Marshal
Posts: 22453
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not particularly GUI related, so I'm going to move this to a more appropriate forum.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the method is using a loop (do-while, while, for) it must read a field variable that should be set by object.stop(). When the variable is setted, the method calls break and stop the loop.

Isn't possible to be sure of what you are doing, but if this is not your case, try reading about wait() and notifyAll() methods from Object class.

Please, be more specific with some samples.
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like method.stop() though! Would that things were so easy! I'm still waiting for the day when we can just explain to the computer what we want it to do, and it would take care of the details.

On the other hand, I suppose I'd be out of a job in that case.

 
reply
    Bookmark Topic Watch Topic
  • New Topic