File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Applet Plugin create two instances of applet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet Plugin create two instances of applet." Watch "Applet Plugin create two instances of applet." New topic
Author

Applet Plugin create two instances of applet.

Rafael Torquato
Greenhorn

Joined: Sep 07, 2008
Posts: 5
Hi all,
I have a applet in the applet constructor i call "JOptionPane.showMessageDialog(null, "Hashcode "+this.hashCode());" and the result are two messages dialog with differents hashcodes.
This happens with both the object tag as the applet tag and the tags created by HtmlConverter.

I'm using ubuntu 9.04 and firefox.
Tags below





Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42935
    
  68
Welcome to JavaRanch.

Don't ever use a constructor in applet. It's up to the browser to instantiate the applet whenever it thinks it's necessary, and the developer should not interfere with that.
Rafael Torquato
Greenhorn

Joined: Sep 07, 2008
Posts: 5
Ulf Dittmer wrote:Welcome to JavaRanch.

Don't ever use a constructor in applet. It's up to the browser to instantiate the applet whenever it thinks it's necessary, and the developer should not interfere with that.


Hi, sorry for my poor english. rssss

I don't was make any applet instance, i didn't call the constructor. The constructor has only a JOptionPane call.

Thanks,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42935
    
  68
By "use" I also meant: You shouldn't put anything in the constructor either. If the browser JVM feels like it, it may call the constructor 100 times, and then discard 99 instances. So just don't use it.
Rafael Torquato
Greenhorn

Joined: Sep 07, 2008
Posts: 5
Ulf Dittmer wrote:By "use" I also meant: You shouldn't put anything in the constructor either. If the browser JVM feels like it, it may call the constructor 100 times, and then discard 99 instances. So just don't use it.


It is true, but it is really strange the browser create two instances of the applet.

Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42935
    
  68
No, it's not strange, even if it created 100 instances. It would be strange if more than a single one was displayed, though.
Rafael Torquato
Greenhorn

Joined: Sep 07, 2008
Posts: 5
Ulf Dittmer wrote:No, it's not strange, even if it created 100 instances. It would be strange if more than a single one was displayed, though.

if more than a single one was displayed, would be very strange. rsss
Because he would need two or more instances?
The problem is that it calls the init twice.
Call WebService twice, etc...

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42935
    
  68
The problem is that it calls the init twice.

Now we're getting somewhere. That, indeed, should not happen. Have you been able to duplicate this behavior with a different browser and/or a different JVM and/or a different operating system?
Rafael Torquato
Greenhorn

Joined: Sep 07, 2008
Posts: 5
Ulf Dittmer wrote:
The problem is that it calls the init twice.

Now we're getting somewhere. That, indeed, should not happen. Have you been able to duplicate this behavior with a different browser and/or a different JVM and/or a different operating system?


With IE8 and Firefox on Windows Vista and the same thing happened.(JVM 1.6.0_14).

With Firefox on Ubuntu 9.04 (JVM 1.6.0_16).

I will try with a different JVM.

Thanks
 
Consider Paul's rocket mass heater.
 
subject: Applet Plugin create two instances of applet.