![rosario.n](https://www.crazyengineers.com/img/avatar.jpg)
Member • Oct 11, 2008
Member • Oct 11, 2008
Member • Nov 30, 2008
import java.awt.*; import java.util.*; import java.applet.*; /* <APPLET CODE="Animation.JAVA" WIDTH=400 HEIGHT=300> </APPLET> */ //The basic applet class.The applet shows 4 cars crossing each other at a square. public class Animation extends Applet implements Runnable { Thread t; //4 variables used to vary the car's positions. int x1=0,x2=380,y1=50,y2=250; public void start() { if(t==null) { t=new Thread(this,"New Thread");//New side Thread created on start of applet. t.start(); } } public void stop() { if(t!=null) { t=null;//On stop of applet the created thread is destroyed. } } //Implementation of method run() of Runnable interface. public void run() { Thread t1=Thread.currentThread(); while(t==t1) { repaint(); try { Thread.sleep(100); } catch(Exception e) { } } } public void paint(Graphics g) { setBackground(Color.cyan); g.setColor(Color.BLACK); x1=(x1+16)%400; x2=x2-16; y1=(y1+12)%300; y2=y2-12; if(y2<0) y2=288; if(x2<0) x2=384; //Draw the roads using 2 filled rectangles using black color. g.fillRect(0,130,400,40); g.fillRect(180,0,40,305); //Draw the white colored lines. g.setColor(Color.white); for(int i=0;i<20;i++) { if(i!=9 && i!=10) g.drawLine(i*20,150,i*20+10,150); } for(int j=0;j<15;j++) { if(j!=7 && j!=8) g.drawLine(200,j*20,200,j*20+10); } //Draw 4 colored cars using filled round rectangles. g.setColor(Color.red); g.fillRoundRect(x2,152,20,8,2,2); g.fillRoundRect(x1,140,20,8,2,2); g.fillRoundRect(190,y1,8,20,2,2); g.fillRoundRect(202,y2,8,20,2,2); } }
Member • Jan 8, 2009
Member • Jan 8, 2009
Member • Jan 9, 2009
Member • Jan 9, 2009
Member • Jan 9, 2009
Member • Jan 10, 2009
Member • Jan 12, 2009
Member • Jan 12, 2009
Member • Jan 23, 2009
Member • Feb 1, 2009
Hey rosario,rosario.nhey..i tried again.there is no error..but,i didn't get the car image..😕
Member • Feb 6, 2009
Member • Aug 1, 2009
Jdk stands for java developing kit... which is an open source software developed by sun microsystem. only with the help of jdk the java source code is compiled into java byte code with the extension of (.class). the command instructing JDK to compile is "javac".lano51hi again i face another problem i try to apply what you wrote but i donot know what is meant by jdk and the .class i donot have it, more over where is the location of the bin in the computer .
i create a file and name it animation.java but the rest of the steps i donot know how to apply it .so please send me the code in a zip file on my mail :
#-Link-Snipped-#
thank you very much for helping me 😁
<html>7. save it with an extension (.html)....in the folder david.
<head>
<title> Display name applet </title>
</head>
<body>
<h1 align=center> Name web applet</h1>
<center>
<applet name="Animation" code="Animation.class" width=200 height=100></applet>
</center>
</body>
</html>
Member • Aug 1, 2009
Member • Aug 1, 2009
Member • Aug 1, 2009
Have you installed JDK?????sppi tried this code but its not working.
it showing an error that applet not initialized.
so can u please check this out
Member • Aug 1, 2009
yah i have installed jdk1.6zia.sepsisHave you installed JDK?????
Member • Aug 1, 2009
Try this:sppyah i have installed jdk1.6
Member • Aug 1, 2009
Member • Aug 20, 2009
Member • Aug 21, 2009
import java.awt.*; import java.util.*; import java.applet.*; /* <APPLET CODE="Animation" WIDTH=400 HEIGHT=300> </APPLET> */ //The basic applet class.The applet shows 4 cars crossing each other at a square. public class Animation extends Applet implements Runnable { Thread t; //4 variables used to vary the car's positions. int x1=0,x2=380,y1=50,y2=250; public void start() { if(t==null) { t=new Thread(this,"New Thread");//New side Thread created on start of applet. t.start(); } } public void stop() { if(t!=null) { t=null;//On stop of applet the created thread is destroyed. } } //Implementation of method run() of Runnable interface. public void run() { Thread t1=Thread.currentThread(); while(t==t1) { repaint(); try { Thread.sleep(100); } catch(Exception e) { } } } public void paint(Graphics g) { setBackground(Color.cyan); g.setColor(Color.BLACK); x1=(x1+16)%400; x2=x2-16; y1=(y1+12)%300; y2=y2-12; if(y2<0) y2=288; if(x2<0) x2=384; //Draw the roads using 2 filled rectangles using black color. g.fillRect(0,130,400,40); g.fillRect(180,0,40,305); //Draw the white colored lines. g.setColor(Color.white); for(int i=0;i<20;i++) { if(i!=9 && i!=10) g.drawLine(i*20,150,i*20+10,150); } for(int j=0;j<15;j++) { if(j!=7 && j!=8) g.drawLine(200,j*20,200,j*20+10); } //Draw 4 colored cars using filled round rectangles. g.setColor(Color.red); g.fillRoundRect(x2,152,20,8,2,2); g.fillRoundRect(x1,140,20,8,2,2); g.fillRoundRect(190,y1,8,20,2,2); g.fillRoundRect(202,y2,8,20,2,2); } }Step #3: Now open command prompt. Switch to your I:\JavaSrcCode directory and enter following command. It will create Animation.class file in the same folder "I:\JavaSrcCode" folder.
javac I:\JavaSrcCode\Animation.java
appletviewer Animation.java
Member • Aug 22, 2009
Member • Mar 23, 2010
Member • Aug 12, 2014
Member • Oct 9, 2014
Member • Aug 14, 2015
Member • Aug 14, 2015
Member • Feb 12, 2016
Member • May 30, 2016