Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 18th, 2012, 07:05 PM
TiT_4_tAt TiT_4_tAt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 1 TiT_4_tAt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 39 sec
Reputation Power: 0
Unhappy Mouse Maze Plz Help...

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)
{

}
}
}

}


I am just a newbie in JAVA programming........
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 host 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.. Well the Applet does not hav a good look as am yet to finesse it :)
Thanks in Advance :)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Mouse Maze Plz Help...


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap