Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple applets invocation from single applet

 
c shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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);
}
}


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic