Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Not taking my mouse clicks fast enough  (Read 1398 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd

Innocent Bystander





« Posted 2006-11-23 02:10:55 »

Ok well i want to make this simple game, and basically all it does is count how many times you clicked, and i made it, but its running too slow. The problem is that its not counting all the clicks, it might have something to do with the way i coded it but idk...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;

public class Countdown extends Applet implements Runnable, MouseListener
{
 Thread th;  
 int i = 200;
 int count = -2;
public void init()
{
    setSize(300,300);
    setBackground(Color.black);
    addMouseListener(this);
}
public void paint(Graphics g)
{
 g.setColor(Color.gray);
 g.drawString("SECONDS LEFT "+i,30,30);
 if(i == 0)
 {
 g.setColor(Color.blue);
 g.drawString("YOU CLICKED "+count+" TIMES!",10,200);
 }
 if(i <= 0)
 {
     g.setColor(Color.red);
     g.drawRect(10,5,150,150);
     stop();
 }
}
public void run()
    {
        while(th == Thread.currentThread())
        {
            i--;
            repaint();
            try{Thread.sleep(50); }
            catch(InterruptedException e){}
        }
    }
    public void start()
    {
       
        if(th == null) th = new Thread(this);
        th.start();
    }
    public void stop()
    {  
     if(th != null) th = null;
    }
    public void mousePressed(MouseEvent e) {
   
    }

    public void mouseReleased(MouseEvent e) {
     
    }

    public void mouseEntered(MouseEvent e) {
       
    }

    public void mouseExited(MouseEvent e) {
       
    }

    public void mouseClicked(MouseEvent e) {
       count++;
       }


ps. im not new to java its just i dont know why its not getting my clicks fast enought and i want to know what i can do...
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2006-11-23 04:59:23 »

mouseClicked is only triggered if you click at the very same spot. So... put the count++ into mousePressed.

弾幕 ☆ @mahonnaiseblog
Offline noblemaster

« JGO Spiffy Duke »


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #2 - Posted 2006-11-23 10:16:55 »

* agrees with oNyx *

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fletchergames

Senior Devvie





« Reply #3 - Posted 2006-11-23 19:35:12 »

If you just hold down the mouse button, mousePressed will be called more than once.  So it will count holding down mouse presses as more than one click.

Why does the count variable start at -2 instead of at 0?

You may want to look into the MouseEvent.getClickCount() method for detecting double clicks (or triple clicks or n-clicks).  I don't think it would help you directly for this example though because each click should have a seperate MouseEvent anyways.
Offline Kova

Senior Devvie





« Reply #4 - Posted 2006-11-23 20:02:53 »

as I see it solution would be to do:

if (!clicked) {
    clicks++;
    clicked = true;
}


in mousePressed() and

clicked = false;

in mouseReleased()
Online kevglass

« JGO Spiffy Duke »


Medals: 195
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2006-11-23 20:42:12 »

Quote
If you just hold down the mouse button, mousePressed will be called more than once.  So it will count holding down mouse presses as more than one click.

Thats isn't true, there's no auto-repeat like there is for keyPressed on some platforms.

You can simply use:

1  
2  
3  
public void mousePressed(MouseEvent e) {
    count++;
}


As I suspect by now you've found out Smiley

Kev

PS: "YOU CLICKED 125 TIMES!"

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (80 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!