I want to use the pause method in the javax.swing.Timer; package but when I call timer.pause(2200); it points to the dot in between timer and pause and says cannot resolve symbol. Does anyone know how to fix this?????
******************SOME OF MY CODE********************** ---------------------------------------------------- ---
public class Creature extends Canvas { private Timer timer; protected Applet applet; private int hitCounter=0; private long pauseTime;
private final int x=(int)(Math.random()*480+1); private final int y=(int)(Math.random()*480+1);
private final int CANVAS_WIDTH = (int)(Math.random()*100+50); private final int CANVAS_HEIGHT = (int)(Math.random()*100+50); private Image img;
public Creature(Applet a)//Allows user to set the rate of Creature as well. { applet=a; int DELAY=(int)(Math.random()*1000+500);//Num=whatever you want it to be. timer=new Timer(DELAY,new CreatureActionListener()); setLocation(x,y); setSize (CANVAS_WIDTH, CANVAS_HEIGHT); addMouseListener(new CreatureMouseListener()); startCreature();
}
public void paint(Graphics screen) { screen.setColor(Color.black); screen.fillRect(x,y,CANVAS_WIDTH, CANVAS_HEIGHT); }
//----------------------------------------------------------------------- //Sets up the MouseListener for the creature. //----------------------------------------------------------------------- private class CreatureMouseListener implements MouseListener { public void mousePressed (MouseEvent event) { if(timer.isRunning())//Checks to see that the timer is running. {
hitCount();//hitCounter++;(Counts the number of hits). applet.showStatus("You got me! "+getHits()+" times."); pauseTime=System.currentTimeMillis(); stopCreature();//timer.stop(); setBackground (Color.yellow);
timer.pause(22000); move(); } } //Empty definitions for unused methods. public void mouseEntered (MouseEvent event) {} public void mouseExited (MouseEvent event) {} public void mouseClicked (MouseEvent event) {} public void mouseReleased (MouseEvent event) {} }
//----------------------------------------------------------------------- //Sets up ActionListener for creature. //----------------------------------------------------------------------- private class CreatureActionListener implements ActionListener { public void actionPerformed (ActionEvent event) { //stopCreature();//timer.stop(); move(); } }
//----------------------------------------------------------------------- //Various methods to do my bidding!!! //-----------------------------------------------------------------------
public void startCreature() { applet.showStatus("Catch me if you can!"); if(!(timer.isRunning()))//(timer.isRunning==false). timer.start(); }
public void stopCreature() { if(timer.isRunning()) timer.stop(); }
public void hitCount() { hitCounter++; }
public void move() { setBackground (Color.black); stopCreature(); int newX=(int)(Math.random()*480+1); int newY=(int)(Math.random()*480+1); setLocation(newX,newY); repaint(); startCreature(); }