The Artima Developer Community
Sponsored Link

Java Answers Forum
pause in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
jake

Posts: 83
Nickname: onorok
Registered: May, 2002

pause in java Posted: May 21, 2002 5:50 PM
Reply to this message Reply
Advertisement
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**********************
---------------------------------------------------- ---

import javax.swing.Timer;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.image.*;

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();
}



public int getHits()
{
return hitCounter;
}

}

Topic: Matt Gerrans ..Your Code is not working Previous Topic   Next Topic Topic: need help pls

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use