Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
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 659 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727

Senior Member


Projects: 2



« 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;
        }
    }  
Online Jimmt
« Reply #1 - Posted 2012-12-18 02:45:07 »

Haven't read your post yet, but use code tags.
Offline Slyth2727

Senior Member


Projects: 2



« Reply #2 - Posted 2012-12-18 02:48:22 »

ok, im new to this site so I dont really know how
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Online Jimmt
« 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

Senior Member


Projects: 2



« Reply #4 - Posted 2012-12-18 02:52:43 »

alright I have done thatt
Online Jimmt
« 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

Senior Member


Projects: 2



« 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.
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

Senior Member


Projects: 2



« 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!
Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (66 views)
2013-05-17 21:29:12

alaslipknot (75 views)
2013-05-16 21:24:48

gouessej (106 views)
2013-05-16 00:53:38

gouessej (103 views)
2013-05-16 00:17:58

theagentd (113 views)
2013-05-15 15:01:13

theagentd (103 views)
2013-05-15 15:00:54

StreetDoggy (148 views)
2013-05-14 15:56:26

kutucuk (171 views)
2013-05-12 17:10:36

kutucuk (169 views)
2013-05-12 15:36:09

UnluckyDevil (178 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.083 seconds with 21 queries.