Tuesday, 2 September 2014

Java Applet program to Display Train

import java.applet.*;
import java.awt.*;
import java.awt.Graphics;

public class Train extends Applet
{
int z=0;
int l=0;
public void paint(Graphics g)
{
setBackground(Color.orange);
setForeground(Color.red);
g.drawString("Designed By Mayank Mehrotra",350,500);



int a[]={460+l,460+l,655+l};
int b[]={200,300,300};
int x[]={460+l,460+l,640+l};
int y[]={210,300,300};

g.setColor(Color.black);
g.fillRoundRect(50+l,200,260,150,30,30);
g.fillRect(305+l,270,30,10);
g.fillArc(70+l,327,50,50,180,180);
g.fillArc(245+l,327,50,50,180,180);
g.fillRoundRect(330+l,200,140,150,30,30);
g.fillRoundRect(430+l,292,228,58,45,35);
g.fillArc(360+l,327,50,50,180,180);
g.fillArc(555+l,327,50,50,180,180);
g.fillPolygon(a,b,3);

g.setColor(Color.white);
g.fillRect(60+l,230,50,90);
g.fillRect(125+l,230,45,45);
g.fillRect(185+l,230,45,45);
g.fillRect(245+l,230,50,90);
g.fillRect(340+l,230,45,45);
g.fillRect(395+l,230,50,90);
g.fillPolygon(x,y,3);

if(l<=1500)
l=l+5;

else
l=0;

try
{
Thread.sleep(100);
repaint();
}
catch(Exception e)
{
}
}
}
/*
<applet code=Train width=1500 height=600>
</applet>
*/

No comments:

Post a Comment