Robotic arm program in java

import java.applet.*;
import java.awt.*;
/*<applet code="robot" height="400" width="500"></applet>*/
public class robot extends Applet implements Runnable{
Thread t=null;
int state;
//int i=250,j=350,k=250,l=250,n=150,o=350;
int m=0;
boolean stopFlag;
int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
public void init() {
x1=100;
y1=450;
x2=150;
y2=350;
x3=250;
y3=250;
x4=350;
y4=250;
x5=50;
y5=450;
x6=450;
y6=330;
setBackground( Color.white );
}
public void start() {
t=new Thread(this);stopFlag=false;
t.start();
}
public void run() {
do{
try {
repaint();
Thread.sleep(100);
x4=x4+2;
y4=y4+2;
x3=x3+1;
y3=y3+1;
x2=x2+1;
y2=y2+1;
m++;
if(stopFlag)
break;
}catch(InterruptedException e){}
}
while(m<49);
do
{try {
repaint();
Thread.sleep(100);
x4=x4-2;
y4=y4-2;
x3=x3-1;
y3=y3-1;
x2=x2-1;
y2=y2-1;
x6=x6-2;
y6=y6-2;
m--;
if(stopFlag)
{
break;
}
}catch(InterruptedException e){}
}while(m>0);
}
public void stop() {
stopFlag=true;
t=null;
}

public void paint( Graphics g )
{
g.setColor( Color.black );
g.drawLine(x1,y1,x2,y2);
g.drawLine(x2,y2,x3,y3);
g.drawLine(x3,y3,x4,y4);
g.drawLine(x5,y5,150,y1);
g.drawLine(x5,y5,x5,y1+10);
g.drawLine(150,y1,150,y1+10);
g.drawLine(x4,y4-25,x4,y4+25);
g.drawLine(x4,y4-25,x4+10,y4-25);
g.drawLine(x4,y4+25,x4+10,y4+25);
g.drawOval(x2-5,y2-5,10,10);
g.drawOval(x3-5,y3-5,10,10);
g.drawOval(x6,y6,40,40);
} }

Robotic arm program in java OUTPUT:

Robotic arm program in java

Robotic arm program in java

Robotic arm program in java1

Robotic arm program in java1

Robotic arm program in java

Robotic arm program in java

 

Facing difficulties in understanding the program ?

Ask Your Queries in Comment Box

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *