• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applet Plugin create two instances of applet.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic