 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Libribex Guest
|
Posted: Mon Dec 22, 2003 5:43 am Post subject: newbie: actionPerformed counting performances? :( |
|
|
Hi,
1.
I'm doing a small dot-catching game applet; it works fine, except that
when you catch the dot and you level up to a more jumpy and smaller
dot (by pushing a button that appears), the values go wrong...
// first, the bit where the button is added
public void mousePressed(MouseEvent e) {
// if mouse pointer was pressed down on dot:
if ( (e.getX() > xPos) & (e.getX() < xPos+diameter) &
(e.getY() > yPos) & (e.getY() < yPos+diameter) ) {
caught = true;
add(levelUpButton);
levelUpButton.addActionListener(this);
this.validate();
}
repaint();
}
// and then when that button is clicked:
public void actionPerformed(ActionEvent e) {
...
if(e.getSource() == levelUpButton) {
dotJumpPower++;
if (diameter > 10) diameter--;
caught = false;
levelUpButton.removeActionListener(this);
remove(levelUpButton);
this.validate();
}
}
So dotJumpPower and diameter should go up and down by just one for
every increase in level. Yet what happens is that the first time you
level up, they are in/decremented by one; the second time by two; the
third time by three; etc.
Can anyone spot why this could be, and how to get rid of it?
2.
Incidentally, is there a better way to check if the click is on my dot
set by
g.fillOval(xPos, yPos, diameter,diameter);
? Now I'm just checking whether the mouse pointer is in an imaginary
/box/ that just covers the oval (see first bit of code), but it would
be nicer if I could check for the exact space of the oval.
Thanks a lot!
-libribex
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Mon Dec 22, 2003 1:28 pm Post subject: Re: newbie: actionPerformed counting performances? :( |
|
|
"Libribex" <Libribex (AT) yahoo (DOT) com> wrote
Hi Libribex.
I might have looked at your code, but it was a snippet!
I tried to compile it and got errors, so no possibility
of help from me (or scores of others who might help,
but won't accept snippets).
So, will I help you if you post a small, self contained,
compilable axample? No. Your problem is beyond
my domain, but you can bet those who _might_ help
you would be more likely to do so.
--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|