Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Mouse Maze..Plz Help

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    }
    }
    }

    }



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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Mouse Maze..Plz Help

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting

    Problem is that the Button on the second screen doesnt appear..
    What is the variable name of the button?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mouse Maze..Plz Help

    The Variable Name is b..

    And for The wrapping up the code, sorry i didnt know it..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Mouse Maze..Plz Help

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting

Similar Threads

  1. BackTracking in a maze
    By skoon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2012, 10:23 AM
  2. problem with a maze program
    By skoon in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 23rd, 2012, 07:04 AM
  3. Maze Game
    By whatsbruin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 15th, 2011, 05:59 PM
  4. need help creating a maze program
    By helpzor in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 2nd, 2011, 03:12 PM
  5. Recursion Maze
    By sman1234 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 28th, 2010, 11:40 AM

Tags for this Thread