Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 945 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;
        }
    }  

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
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.

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline h3ckboy

JGO Coder


Medals: 5



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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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.

pw (12 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!