This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Multiple applets invocation from single applet

 
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);
}
}


 
    Bookmark Topic Watch Topic
  • New Topic