Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button listener problems

Status
Not open for further replies.

richATrichardjones

Technical User
Joined
Sep 22, 2002
Messages
24
Location
GB
Hi

I have three buttons on a GUI I have designed. The first is called connect which connects to a proxy server. The second is called disconnect which disconnect and the third is called sweep which send the string sweep to the proxy server.

I have a class called ProxyServer. When I press connect I create an instance of that class. That is ProxyServer serverone = new ProxyServer();

When I press disconnect I want to delete this object. How do I do that?

When I press sweep I want to call a function called getResults() from within the proxy server class. Hence I want to call serverone.getResults(). However from within the sweepListener it does not recognise serverone. At the moment each button has its own listener so everything is independent. What I want to do is have serverone recognisable for each button listener. Therefore I can get the restuls and also delete the object. How do I do this?

Thanks for any help
Richard
 
Okay, if your listeners are not inner classes of your GUI as I have typically seen done, then I'd override the constructor for your listeners to take the ProxyServer object. Objects are pass by reference so it'll have that object to work with. That should take care of your recongizing problem, you could always just make the listeners inner classes of your GUI too, where I guess that's where you're creating your ProxyServer from. If I'm not mistaken, there are not lost memory concerns in java or at least not very wide. I'd call a shutdown type method on your ProxyServer to clean up the connection and close it and do whatever else you need then set the reference (serverone) to null and I would think the garbage collector at this point would collect the previous instance. Hope that helps.

JavaDude32
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top