Hi, someone asked me a question the other day and I got curious myself. The problem he has is this: he's running Netscape to try out an applet he made, but when he closes Netscape he found out that the system isn't giving him back all the resources. He has to kill the process with Ctrl-Alt-Del (he's running 95). Looks like a thread is still active. Now this should be handled with stop() and destroy() I think. Could anyone give me an example in the form of a small very simple applet where explicitly destroy() is used to make sure all threads are killed (sounds kinda violent eh?). I appreciate it! Patrick
Thanks for your reaction. I will ask this question to the person who asked me the question. Is there a general way though where you can explicitly tell the applet to destroy itself (and thus all it's threads/processes)? Appreciate the input!! Patrick
humm,yes, that's what I suspected, but what would this look like? Suppose you have the applet that I will add here after, how would you use the destroy() method? I would appreciate it if someone could rebuild this code so the applet will explicitly destroy itself. Thanks! import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MoveMe extends JApplet { Container theContainer; JButton theButton; public void init() { theContainer = this.getContentPane(); theContainer.setLayout(null); theButton = new JButton("Move Me With the Mouse"); theContainer.addMouseMotionListener(new Chaser()); theContainer.add(theButton); theButton.setBounds(0, 0, 150, 35); } public class Chaser extends MouseMotionAdapter { public void mouseMoved(MouseEvent me) { theButton.setSize( 150 + me.getX(), 35 + me.getY() ); theButton.setLocation(me.getX()+3, me.getY()+3); } } }
Originally posted by Patrick Lentz: humm,yes, that's what I suspected, but what would this look like? Suppose you have the applet that I will add here after, how would you use the destroy() method? I would appreciate it if someone could rebuild this code so the applet will explicitly destroy itself. Thanks! import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MoveMe extends JApplet { Container theContainer; JButton theButton; public void init() { theContainer = this.getContentPane(); theContainer.setLayout(null); theButton = new JButton("Move Me With the Mouse"); theContainer.addMouseMotionListener(new Chaser()); theContainer.add(theButton); theButton.setBounds(0, 0, 150, 35); } public class Chaser extends MouseMotionAdapter { public void mouseMoved(MouseEvent me) { theButton.setSize( 150 + me.getX(), 35 + me.getY() ); theButton.setLocation(me.getX()+3, me.getY()+3); } } }
Since you don't have any threads or let's say Graphics object to kill how about this?: public void distroy() { theContainer = null; theButton = null; }