Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

applet & destroy()

 
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
 
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
 
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);
}
}
}
 
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
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic