Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run Two Applets Together.

 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5147
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5147
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic