AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

newbie: actionPerformed counting performances? :(

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Libribex
Guest





PostPosted: Mon Dec 22, 2003 5:43 am    Post subject: newbie: actionPerformed counting performances? :( Reply with quote



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





PostPosted: Mon Dec 22, 2003 1:28 pm    Post subject: Re: newbie: actionPerformed counting performances? :( Reply with quote



"Libribex" <Libribex (AT) yahoo (DOT) com> wrote

Quote:
Hi,

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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.