Results 1 to 5 of 5

Thread: wierd problem

  1. #1
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Exclamation wierd problem

    ok so i am working on a fps. i hit a bit of a snag and i need some help. what i am doing is this
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class DotsPanel extends JPanel
    {
    	private final int WIDTH=500, HEIGHT=500;
    	private final int RADIUS=2;
    	private ArrayList pointList;
    	
    	
    	private int count;
    
        public DotsPanel() 
        {
        	pointList = new ArrayList();
        	count=0;
        	
        	addMouseListener (new DotsListener());
        	
        	setBackground (Color.black);
        	
        
        }
        public void paintComponent (Graphics page)
        {
        	super.paintComponent(page);
        	page.setColor (Color.red);
        	
        	
        	Iterator pointIterator= pointList.iterator();
        	while (pointIterator.hasNext())
        	{
        		Point drawPoint= (Point) pointIterator.next();
        	
        	page.fillOval (drawPoint.x - RADIUS, drawPoint.y-RADIUS,RADIUS*2, RADIUS*2);
        	page.setColor (Color.red);
        	
        	page.setColor (Color.black);
        	page.fillOval (drawPoint.x - RADIUS, drawPoint.y-RADIUS,RADIUS*2, RADIUS*2);
        	
        	}
        	page.setColor (Color.red);	
        	page.drawString ("Number of clicks!: "+count, 5, 15);
        	if (count==6)
        	{
        		page.drawString("Reload!", 80, 25);
        	}	
        }
        
        private class DotsListener implements MouseListener
        {
        	public void mousePressed (MouseEvent event)
        	{
        	pointList.add (event.getPoint());
        	count++;
        	if (count==7)
        	{
        		
        		count=0;
        	}
        	repaint();
        	}
        
        
        public void mouseClicked (MouseEvent event) {}	
        public void mouseReleased (MouseEvent event) {}
        public void mouseEntered (MouseEvent event) {}
        public void mouseExited (MouseEvent event) {}
        
        }
        
    }
    i want to know is there any way i can pause the count until the player presses a button on the keyboard.

    thank you for your help!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default

    pause the count until
    What causes count to change? Is it Only when the mouse is pressed? Does pausing the count mean NOT to change it until ...?
    You could use a flag to control the changing of count.
    Have the button press change the flag to allow the count to continue.

  3. #3
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Default

    the thing i want it to do is stop counting the clicks until the person playing presses "R".

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Do what Norm suggests. Set the reload flag to true initially, but when the user hits the maximum number of clicks, set reload to false. In the mousePressed method, only register clicks if reload is true. Then use key bindings to set reload back to true if the user presses "r" or "R".

  5. #5
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

Posting Permissions

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