JAD
02-02-2008, 10:19 PM
Well, here's the code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import java.util.Random;
public class MyFightingGame extends JApplet implements Runnable, MouseListener, MouseMotionListener
{
private int x1;
private int x2;
Thread animator;
private String clickNum;
private boolean first;
private boolean clicked;
// private Random r;
public void init()
{
JRootPane rootPane = this.getRootPane();
rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
addMouseListener(this);
addMouseMotionListener(this);
}
public void start()
{
animator = new Thread(this);
animator.start();
first = true;
clicked = false;
}
public void stop()
{
animator = null;
}
public void mainMenu(Graphics g)
{
if(first == true)
{
g.setColor(Color.blue);
Font myFont = new Font("Times New Roman", Font.BOLD, 30);
g.setFont(myFont);
g.drawString("Click anywhere to play!", 100, 200);
while(clicked == false && Thread.currentThread() == animator)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
break;
}
}
first = false;
g.drawString("hi there",17,17);
}
}
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
mainMenu(g);
}
public void run()
{
while(Thread.currentThread() == animator)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
break;
}
repaint();
}
}
public void mouseDragged(MouseEvent me)
{
}
public void mouseMoved(MouseEvent me)
{
}
public void mouseEntered(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public void waitMainMenu()
{
clicked = true;
}
public void mousePressed(MouseEvent me)
{
waitMainMenu();
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
}
}
It's nothing really yet, I just started writing something and already I'm having problems. When I run the applet, it's supposed to do the mainmenu method once, and what the mainmenu method is supposed to do is draw the string "Click anywhere to play!" and wait until clicked = true (clicked is supposed to equal true when the mouse is clicked anywhere in the applet), then draw the string "hi there". But what it does is draws both strings because for some reason it's not waiting for the mouse to be clicked :confused:
In theory this should work, but I don't know what the problem is.
Thanks in advance. Any help/ideas/suggestions are greatly appreciated!
~JAD
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import java.util.Random;
public class MyFightingGame extends JApplet implements Runnable, MouseListener, MouseMotionListener
{
private int x1;
private int x2;
Thread animator;
private String clickNum;
private boolean first;
private boolean clicked;
// private Random r;
public void init()
{
JRootPane rootPane = this.getRootPane();
rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
addMouseListener(this);
addMouseMotionListener(this);
}
public void start()
{
animator = new Thread(this);
animator.start();
first = true;
clicked = false;
}
public void stop()
{
animator = null;
}
public void mainMenu(Graphics g)
{
if(first == true)
{
g.setColor(Color.blue);
Font myFont = new Font("Times New Roman", Font.BOLD, 30);
g.setFont(myFont);
g.drawString("Click anywhere to play!", 100, 200);
while(clicked == false && Thread.currentThread() == animator)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
break;
}
}
first = false;
g.drawString("hi there",17,17);
}
}
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
mainMenu(g);
}
public void run()
{
while(Thread.currentThread() == animator)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
break;
}
repaint();
}
}
public void mouseDragged(MouseEvent me)
{
}
public void mouseMoved(MouseEvent me)
{
}
public void mouseEntered(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public void waitMainMenu()
{
clicked = true;
}
public void mousePressed(MouseEvent me)
{
waitMainMenu();
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
}
}
It's nothing really yet, I just started writing something and already I'm having problems. When I run the applet, it's supposed to do the mainmenu method once, and what the mainmenu method is supposed to do is draw the string "Click anywhere to play!" and wait until clicked = true (clicked is supposed to equal true when the mouse is clicked anywhere in the applet), then draw the string "hi there". But what it does is draws both strings because for some reason it's not waiting for the mouse to be clicked :confused:
In theory this should work, but I don't know what the problem is.
Thanks in advance. Any help/ideas/suggestions are greatly appreciated!
~JAD