Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applet & destroy()

 
Patrick Lentz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nitin Shivaram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could u elaborate as to which process is still running after closing the Netscape browser?
Nitin

------------------
Anthrax
 
Patrick Lentz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Suneel Setlur
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call explicitly the applet's destroy method in your code.
------------------
Suneel
 
Patrick Lentz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
}
 
Max Punch
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
}

 
Max Punch
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
Suneel Setlur
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
This is based on swing.
Try this. It works
public void remove(){
remove(theContainer);
}
Regards
Suneel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic