This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Applets and the fly likes How to run Two Applets Together. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "How to run Two Applets Together." Watch "How to run Two Applets Together." New topic
Author

How to run Two Applets Together.

Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

I wrote two applets both runs perfectly alone.
But when I alter my html file like


only TrafficLight applet runs..
why ,please solve my problem..


OCPJP 6 86%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41626
    
  55
There's no reason why multiple applets wouldn't work on the same page; see http://www.cs.ubc.ca/~harrison/Java/sorting-demo.html for an example. Are there any exceptions in the Java Console?


Ping & DNS - my free Android networking tools app
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

No Sir no any Exception in console...
i more thing i notice that when i extend both of my classes from Applet the problem occurs.
But when i extend them from JApplet the both applets runs but looks like browser ramdomly selects between them Because i am getting ramdom applets.
Should i post my code here ??
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

No, don't post your code just yet. Create two very simple Applets, each with only a label with differing text -- maybe "One" and "Two" -- and use the same HTML to display them on one page.

If that works, start trying to figure out what's different about the two Applets that gave you a problem. If it doesn't, post the entire code of those two simple Applets along with the entire HTML so we can try it out for ourselves to see what might be the constraint.


luck, db
There are no new questions, but there may be new answers.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2053
Also try to position them explicitly. They could be display one on top of the other, hiding the other one.

Just to test this possibility, put them inside a <table> on different <td>.
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Got the problem guys......
Actually I was using Thread.sleep() in an infinite loop to achieve animation in both applets in the paint method thats why if one loads then another missing.
now I fixed it and now its running properly...
Thanks for replies and for your valuable time.....
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

Hasn't anyone told you yet to use a javax.swing.Timer for animation?

Also, keep painting methods strictly for painting. Use a Timer to change state and call repaint().

Recommended tutorials:
Performing Custom Painting
How to Use Swing Timers
Concurrency in Swing
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Darryl Burke wrote:Hasn't anyone told you yet to use a javax.swing.Timer for animation?

Also, keep painting methods strictly for painting. Use a Timer to change state and call repaint().

Recommended tutorials:
Performing Custom Painting
How to Use Swing Timers
Concurrency in Swing


Thanks Derryl..
No, actually I am a newbie no one told me to use java.swing.Timer
So, thanks a lot for accurate answers.
 
Don't get me started about those stupid light bulbs.
 
subject: How to run Two Applets Together.