Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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  
  Mouse Input Per Second on Button Problems  (Read 895 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2012-12-18 02:27:59 »

I have a java game that I get mouse actions in. I have a point msc in my main class, msc gets changed whenever I press the mouse and gets set to 0, 0 whenever I release he mouse. For my buttons that I coded, they check if the msc is inside their rectangle and if so call click. I have a button that toggles a Boolean and as a result of that when I click on it it switches true and false very fast because the msc gets updated every time paintComponent is called. I would like to know how i could click it and have it switch once, then click it and switch again and so forth.

Here is the code for the button click method:

      
1  
2  
3  
4  
5  
6  
7  
8  
9  
 if (button.contains(Screen.msc)) {
            beenClicked = true;
            this.width = this.width - 2;
            this.height = this.height - 2;
            this.x = this.x + 1;
            this.y = this.y + 1;
            g.setColor(currColor);
            textColor = Color.YELLOW;
        }

but that is not where the problem is I think. Here is the code that changes msc:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void mouseReleased(MouseEvent e) {
    Screen.msc = new Point(0, 0);
}



    public void mousePressed(MouseEvent e) {
    Screen.msc = new Point((e.getX()) - ((Frame.size.width - Screen.myWidth) / 2), e.getY() - ((Frame.size.height - (Screen.myHeight)) - (Frame.size.width - Screen.myWidth) / 2));
}

and the code for what happens when the specific toggle button is clicked:

1  
2  
3  
4  
5  
6  
7  
    if (toggleToolTips.clicked()) {
        if (Screen.canDrawTooltip) {
            Screen.canDrawTooltip = false;
        } else if(!Screen.canDrawTooltip){
            Screen.canDrawTooltip = true;
        }
    }  

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2012-12-18 02:45:07 »

Haven't read your post yet, but use code tags.
Offline Slyth2727
« Reply #2 - Posted 2012-12-18 02:48:22 »

ok, im new to this site so I dont really know how

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2012-12-18 02:49:38 »

Highlight your code and press the button with the # symbol (it's in the row of buttons directly above the emoticons)
Offline Slyth2727
« Reply #4 - Posted 2012-12-18 02:52:43 »

alright I have done thatt

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #5 - Posted 2012-12-18 02:57:55 »

If you want a on/off switch GUI component the easy way would be to use a JRadioButton or JCheckBox.
Or if you want to stick something more like a JButton use a JToggleButton.
Offline Slyth2727
« Reply #6 - Posted 2012-12-18 03:15:54 »

well I am hardcoding all of the gui elements to the game myself to get as much control as possible and it is also a good learning experience for me.

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Offline h3ckboy
« Reply #7 - Posted 2012-12-18 07:05:44 »

in the spot where you change the boolean for visible you could make the code something like this:

1  
2  
3  
4  
5  
6  
7  
if(msc.x==0&msc.y==0&isVisible==true)
{
isVisible=false;
}else if(isVisible==false)
{
isVisible= true;
}



Is that what you're looking for?
Offline Slyth2727
« Reply #8 - Posted 2012-12-19 00:27:33 »

YES! Thank you very much I felt like such an idiot after seeing this! This solved it!

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
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.

xsi3rr4x (50 views)
2014-04-15 18:08:23

BurntPizza (46 views)
2014-04-15 03:46:01

UprightPath (62 views)
2014-04-14 17:39:50

UprightPath (44 views)
2014-04-14 17:35:47

Porlus (61 views)
2014-04-14 15:48:38

tom_mai78101 (84 views)
2014-04-10 04:04:31

BurntPizza (142 views)
2014-04-08 23:06:04

tom_mai78101 (242 views)
2014-04-05 13:34:39

trollwarrior1 (201 views)
2014-04-04 12:06:45

CJLetsGame (208 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!