This is my code..
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
* <html>
* <head>
* <title>My Game</title>
* </head>
* <body>
* <applet code="C.class" width=500 height=410></applet>
* </body>
* </html>
*/
public class C extends Applet implements
ActionListener,MouseMotionListener,Runnable
{
Button b;
Label l1,l2,l3;
Font f;
AudioClip au;
int min,sec;
Thread t;
int xpos,ypos,ht,wd;
boolean failed,success,button;
public void initialise()
{
l1=new Label("Move The Pointer Without Touching The Sides : ");
min=sec=0;
au=getAudioClip(getDocumentBase(),"");
t=new Thread(this,"Timer");
setBackground(Color.black);
setForeground(Color.white);
f=new Font("Trash",Font.BOLD|Font.ITALIC,16);
setFont(f);
try
{
Thread.sleep(1500);
}catch(Exception e)
{
}
addMouseMotionListener(this);
t.start();
add(l1);
success=false;
failed=false;
button=true;
}
public void start()
{
initialise();
}
public void mouseDragged(MouseEvent e)
{
}
public void mouseMoved(MouseEvent e)
{
xpos=e.getX();
ypos=e.getY();
if(!((xpos>=0 && ypos>200 && xpos<=70 && ypos<=230) ||
(xpos>70 && xpos<=80 && ypos<220 && ypos>=160) || (xpos>70 &&
xpos<=200 &&
ypos<160 && ypos>=150) || (xpos>200 && xpos<=210 && ypos>150
&& ypos<=310) || (xpos>210 && xpos<=300 && ypos<310 &&
ypos>300)))
{
failpaint();
}
if(xpos>285 && xpos<355 && ypos <340 && ypos>270)
{
successpaint();
}
}
public void failpaint()
{
removeMouseMotionListener(this);
failed=true;
repaint();
}
public void successpaint()
{
removeMouseMotionListener(this);
success=true;
repaint();
}
public void paint(Graphics g)
{
if(!failed && !success)
{
g.setFont(new Font("Harlow Solid Italic",Font.BOLD,20));
g.setColor(Color.white);
g.fillRect(0,200,70,30);
g.fillRect(70,160,10,60);
g.fillRect(70,150,130,10);
g.fillRect(200,150,10,160);
g.fillRect(210,300,90,10);
g.setColor(Color.LIGHT_GRAY);
g.fillRect(285,270,70,70);
g.setColor(Color.white);
g.drawString("Reach Here ! ",310,300);
g.setFont(new Font("Algerian",Font.BOLD|Font.ITALIC,25));
g.drawString("Time - " + min + " : " + sec, 40,380);
}
else if(failed && button)
{
remove(l1);
g.setFont(new Font("Algerian",Font.BOLD|Font.ITALIC,25));
g.setColor(Color.white);
g.drawString("YOU LOST !!!",110,190);
g.setFont(f);
g.setColor(Color.white);
button=false;
addButton();
}
else if(success && button)
{
g.setColor(Color.white);
remove(l1);
g.setFont(new Font("Algerian",Font.BOLD|Font.ITALIC,18));
g.drawString("YOU WON !!! And You Took " + min + " Mins and "
+ sec + " Secs !!",10,190);
g.setFont(f);
g.setColor(Color.white);
button=false;
addButton();
}
}
public void addButton()
{
b=new Button("Retry");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b)
initialise();
}
public void run()
{
while(!success && !failed)
{
try
{
repaint();
sec++;
if(sec>=60)
min++;
Thread.sleep(1000);
}
catch(InterruptedException e)
{
}
}
}
}
What I am trying to do is to create a mouse maze and if the user wins or loses it, I display another Screen dislaying that he has won or has lost and add one more button "Retry" to start from the first.. Maze works fine but my Problem is that the Button on the second screen doesnt appear... Plz run the applet for more details (Play The Game after bringing the applet Window to middle of the screen to start from left of the window).. Well the Applet does not hav a good look as am yet to finesse it :)
Thanks in Advance :)