From: Gary S. <gi...@st...> - 2003-02-17 14:43:37
|
On Mon, 17 Feb 2003, oO=D5 --- Le Castor --- =D5Oo wrote: > I tried to do what you said, but there one thing I > must be missing, because I don't know how to insure > that the termination comes from the canvas. I tried to > do it inside a windowClosed event, but it doesn't > work... > Yeah, I think I might have been smoking something when I wrote that :). My actual final solution was to put the window closing inside the same class that I do all my drawing from (so the class that extends GLAmimCanvas). So say you have the class Game which is the main canvas (and does all the drawing) then you get: public class Game extends GLAnimCanvas implements =09=09=09=09=09java.awt.event.WindowListener =09{ public void windowClosed(WindowEvent e) { System.exit(0); } public void windowClosing(WindowEvent e) { System.exit(0); } =09/**And the rest of your functions*/ } (window closing is always called first so it should never get to closed). anyway so you create your frame add the canvas to it and then add the event listener like: frame.addWindowListener(Game.getInstance()); where the reference is the currently active canvas frame (my program uses the singleton pattern). You can also terminate things safely using the key listeners and such like. I hope this helps, Gary |