Forums Register Login

Multiple applets invocation from single applet

+Pie Number of slices to send: Send
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);
}
}


But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 843 times.
Similar Threads
dumb array definition error, help!!!
Method call from mouseClicked
Can you give sample code to draw rectangle etc., etc.,?
Newbie in need of help
Need help on two compile errors
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:48:41.