Results 1 to 7 of 7

Thread: Timer problem

  1. #1
    djokovic is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Timer problem

    Why I can't create constructor(Timer) ?

    Java Code:
    public class monster extends JPanel{
    	
    	private BufferedImage monster;
    	private int x;
    	private int y;
    	private Timer timer;
    	final int TIME = 50;
    	
    	public monster(){
    		timer = new Timer(TIME, new timeListener());
    		x = 0;
    		y = 0;
    		try{
    			monster = ImageIO.read(new File("target.jpg"));
    		}catch(IOException e){
    			
    		}
    	}
    	public void paintComponent(Graphics g){
    		g.drawImage(monster,x,y,null);	
    	}
    	
    	private class timeListener implements ActionListener{
    		public void actionPerformed(ActionEvent arg0) {
    			
    		}
    		
    	}
    }
    Error says that this type constructor is undefined, but I can swear, that I saw exactly same constructor in book and Java API.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,858
    Rep Power
    8

    Default Re: Timer problem

    Please use standard naming conventions- class names start with an upper-case letter, methods and variables with a lower-case letter.

    What kind of Timer is that? Which constructor are you trying to call? What kind of values are you passing into the constructor? What's your actual error message?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,858
    Rep Power
    8

    Default Re: Timer problem

    Also, when do you import the proper Timer class?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: Timer problem

    What is the full error you get and the line on which that error occurs?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    djokovic is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: Timer problem

    Quote Originally Posted by Tolls View Post
    What is the full error you get and the line on which that error occurs?
    Full error is : The constructor Time(int, monster.timeListener) is undefined.

    I want to pass int for miliseconds and ActionListener. I used exactly same line as in Java foundations book. But with different constant name and different Listener class.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: Timer problem

    And in answer to Kevin?
    What Timer class is that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default Re: Timer problem

    @djokovic: Instead of using "import java.util.Timer" you should use import javax.swing.Timer;

Similar Threads

  1. Timer Problem
    By ellias2007 in forum New To Java
    Replies: 1
    Last Post: 10-20-2011, 10:04 PM
  2. Replies: 15
    Last Post: 11-15-2010, 08:29 PM
  3. Replies: 0
    Last Post: 04-04-2008, 02:46 PM
  4. Problem with timer in java
    By paul in forum Advanced Java
    Replies: 3
    Last Post: 07-26-2007, 10:18 AM
  5. problem with timer
    By Marcus in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 05:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •