• 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

Multiple applets invocation from single applet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing translation of car using applets.
I have a car in first applet and in the next applets car moves slightly.(Total 5 applets.car moves from x=50 to x=250.)
I am not able to call those applets from my main applet.I am not using repaint because i want to show car movement in different windows(frames).
I have written code for 2 applets.I think i am wrong in calling paint of second applet from my first applet.
can i do this using java swings?
Please guide me.
\\Main applet
import java.applet.*;
import java.awt.*;

public class HelloWorldApplet extends Applet
{
private int x, y;

public void init( )
{
x = 50;
y = 50;
}

public void paint(Graphics g)
{
g.drawRect(x, y, 200, 100);
setBackground(Color.black);
g.setColor(Color.RED);
g.fillRect( x, y, 200, 100 );
g.drawOval(55,150,40,40);
g.drawOval(205,150,40,40);
g.fillOval(55,150,40,40);
g.fillOval(205,150,40,40);

}
Applet2 secondApp = (Applet2)getAppletContext().getApplet("secondapplet");
secondApp.draw();


}
\\Applet which is to be invoked.
import java.applet.*;
import java.awt.*;

public class Applet2 extends Applet
{
private int x, y;
Graphics a;
public void init( )
{
x = 90;
y = 50;
}
public void draw()
{
paint(a);
}
public void paint(Graphics g)
{
g.drawRect(x, y, 200, 100);
setBackground(Color.black);
g.setColor(Color.RED);
g.fillRect( x, y, 200, 100 );
g.drawOval(95,150,40,40);
g.drawOval(245,150,40,40);
g.fillOval(95,150,40,40);
g.fillOval(245,150,40,40);
}
}


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic