You are not logged in.
Pages: 1
I'm writing a java application in netbeans and I've stumbled upon a problem I have no idea how to solve.
In my main code I'm starting a second, maximized frame and adding Canvas extending class that interacts with a user and draws stuff accordingly. The problem is at some point that canvas is supposed to tell the main application that it's finished, so the second frame can be closed and the data that was gathered during canvas action analyzed and I have no idea how to do that, since canvas can't see anything outside itself.
Any hints?
Offline
You could create a isFinished()-method in your canvas-class. And in the class where you run the canvas-class you could have a
while(c.isFinished() == false) { Thread.sleep(1000); }
So it will ask each second if the canvas is finished.
I'm not really sure if its the best way for you. Maybe you should think about redesigning your classes. There is always a good solution.
Offline
I've tried that ealier, but unfortunately nothing in second frame is happening as if sleep() clogs everything.
Offline
Something with SwingWorker, perhaps? I am not a Java programmer.
Offline
Oh SwingWorker seems like something that might help. I'll try to get familiar with it today and post results. Thanks
Offline
I'm not sure I completely understand the problem ....
Have you tried writing a short, static, public method in the main file that the canvas-class could call when finished? So, canvas could call the "imFinished()" method of the main class, and that "imFinished()" method could do the closing? Being static and public, there is no way(that I can think of) that the canvas class _couldnt_ see it.
-- Drew
Offline
I think you're completely right Drew, I was thinking about something like that too, but it didn't occur to me that I could make that method static to solve the visibility problem.
Thank you.
Edit:
However there's no way to call nonstatic methods or variables from the instance of my main class from the public static method.
Last edited by xaff (2009-03-14 10:22:20)
Offline
You could make the canvas part Observable (if it is a and simply add you main class (or an anonymous class inside your main routine) as a Observer.
http://en.wikipedia.org/wiki/Observer_pattern
Offline
True. Getters/Setters, or maybe throw the canvas inside the main routine ?
--edit--
Or try playing around with making the variables/methods protected instead of private. that would open them up to members of the same package + subclasses.
Last edited by drewbug01 (2009-03-15 22:52:14)
Offline
Pages: 1