Find us on Google+ Kill the code: Ball rolling in the TUNNEL

Wednesday, 7 March 2012

Ball rolling in the TUNNEL


/* Make the ball float in tunnel and apply password mechanism...*/


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="rolling_fun12" width=1000 height=300>
</applet>
*/


public class rolling_fun12 extends Applet implements Runnable,KeyListener {
String msg="";
String password="nisarg"; /*THIS IS YOUR PASSWORD STRING...*/
char c;
boolean correct=false;
int i=0;
int finish=0;
public void init() {
addKeyListener(this);
requestFocus();
t=new Thread(this);
}
public void keyPressed(KeyEvent ke) {
showStatus("key Pressed.");
/*c=ke.getKeyChar();
check=true;
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}*/
//if(msg.equals(password)) showStatus("VALID PASSWORD.");
//showStatus("key Pressed.");
}
public void keyReleased(KeyEvent ke) {
if(finish==1) showStatus("THE OUTPUT IS ON THE SCREEN.");
else if(msg.equals(password)) {
showStatus("VALID PASSWORD.");
repaint();
}
}
public void keyTyped(KeyEvent ke) {
if(finish==1) showStatus("THE OUTPUT IS ON THE SCREEN.");
else {
showStatus("Key Typed.");
//showStatus("Key Typed.");
c=ke.getKeyChar();
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}
if(msg.equals(password)) {
correct=true;
repaint();
showStatus("VALID PASSWORD.");
}
repaint();
}
}
Thread t;
int start=180;
int end=350;
int x=300;
int y=225;
int end1=0,end2=0,end3=0;
int flag=0,flag2=0;
int slide1=0,drop=0,slide2=0,remain=0,enter=0,once=0;
Color c1=new Color(255,0,255);
/*public void init() {
t=new Thread(this,"first");

}*/

public void start() {
t.start();
}

public void run() {
for(;;) {
if(end3<1460) {
slide2=1;
repaint();
}
else if(end2<1650) {
drop=1;
slide2=0;
repaint();
}
else if(end1<1350) {
drop=0;
slide1=1;
repaint();
}
else {
remain=1;
slide1=0;
slide2=0;
drop=0;
repaint();
}
}
}
public void paint(Graphics g) {
if(correct) {
g.drawLine(15,100,150,100);
g.drawLine(150,100,150,260);
g.drawLine(151,260,325,260);
g.drawLine(200,58,200,218);
g.drawLine(15,58,200,58);
g.drawLine(326,260,326,219);
g.drawLine(326,218,200,218);
if(slide1==1)
{
try {

start=start+15;
end=end+15;
//g.drawArc(x,59,40,40,start,360);
g.setColor(c1);
if(enter==0) {
g.fillArc(x,y,40,40,/*start*/0,360);
enter=1;
}
else {
g.fillArc(x,y,40,40,/*start*/start,353);
enter=0;
}
x=x-5;

if(start>350) {
start=0;
end=350;
}
//if(x>230) x=10;
//if(end1<1350) 
//{
end1+=50;
Thread.sleep(60);
slide1=0;
repaint();
//showStatus("end = "+end);

//}
//flag2=1;
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(drop==1) {
try {
start=start+15;
end=end+15;
//x=155;
//y=y+40;
//g.drawArc(x,y,40,40,start,360);
g.setColor(c1);
if(enter==0) {
g.fillArc(x+2,y,40,40,/*start*/0,360);
enter=1;
}
else {
g.fillArc(x+2,y,40,40,/*start*/start,353);
enter=0;
}
y=y-5;

if(start>350) {
start=0;
end=350;
}
//if(y>295) y=150;
//if(end2<700) 
//{
end2+=50;
drop=0;
repaint();
//showStatus("end = "+end);
Thread.sleep(100);
//}
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(slide2==1)
{
try {

start=start-15;
end=end+15;
//g.drawArc(x,y-5,40,40,start,360);
g.setColor(c1);
if(enter==1) {
g.fillArc(x,y-5,40,40,/*start*/0,360);
enter=0;
}
else {
g.fillArc(x,y-5,40,40,/*start*/start,353);
x=x-5;
}
if(start>350) {
start=0;
end=350;
}
//if(x>230) x=10;
//if(end1<1350) 
//{
end3+=50;
Thread.sleep(60);
slide1=0;
slide2=0;
repaint();
//showStatus("end = "+end);

//}
//flag2=1;
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(remain==1) {
//g.drawArc(x-5,y-5,40,40,0,360);
g.setColor(c1);
finish=1;
if(once==0) {
showStatus("PROGRAM ENDED.");
once=1;
}
g.fillArc(x+5,y,40,40,0,360);
try {
Thread.sleep(500);
} catch(InterruptedException e) {

}
}
}
else {
g.drawString("ENTER VALID PASSWORD.",40,40);
try {
Thread.sleep(3000);
} catch(InterruptedException e) {

}
}
}
}

No comments:

Post a Comment