Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  [SOLVED] MouseClicked event not registering on a certain button  (Read 523 times)
0 Members and 1 Guest are viewing this topic.
Offline Rhys Campbell

Senior Newbie


Projects: 1



« Posted 2014-03-29 03:56:04 »

I'm really stuck on this stupid bug. I've tried absolutely everything to fix it. I made my own dialog box with 3 buttons and some text. It lets you choose a size for my game's layout. The two buttons that let you change the size work perfectly, but the "ok" button doesn't even register.

This is the dialog box


Here's the code:
http://pastebin.java-gaming.org/7a843088283
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2014-03-29 03:59:54 »

Ok... so where do you ever call mouseClicked() then? We need all the relevant code, not short little snippets.

Offline Rhys Campbell

Senior Newbie


Projects: 1



« Reply #2 - Posted 2014-03-29 04:29:44 »

Ok... so where do you ever call mouseClicked() then? We need all the relevant code, not short little snippets.

Hopefully this should cover it all
http://pastebin.java-gaming.org/a8438128386
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ewg

Junior Member


Medals: 7


Java games rock!


« Reply #3 - Posted 2014-03-29 07:46:47 »

Typo? :
   public BTN_Go btnGo = new BTN_Go("btn_go.png");
   public BTN_Go btnStop = new BTN_Go("btn_stop.png");   

Should that second line be BTN_Stop?
Offline Rhys Campbell

Senior Newbie


Projects: 1



« Reply #4 - Posted 2014-03-30 11:02:50 »

Typo? :
   public BTN_Go btnGo = new BTN_Go("btn_go.png");
   public BTN_Go btnStop = new BTN_Go("btn_stop.png");   

Should that second line be BTN_Stop?


That's fine. It's meant to be like that. I just have messy coding.
Offline ewg

Junior Member


Medals: 7


Java games rock!


« Reply #5 - Posted 2014-03-30 11:32:32 »

It looks like you set some variables like "active" in the mouse handlers on the AWT thread and then access them on your other thread.  When you do this you need to set the variables to volatile or use some other form of serialization.  This is because of the visibility limitations in the java memory model, so each thread can keep a local copy of any variable and they may or may not sync the local copys until there is a memory barrier. Volatile read/write or synchronize statements cause these memory barriers.

So try changing the "active" variable to be volatile and see if that changes anything.
Offline Rhys Campbell

Senior Newbie


Projects: 1



« Reply #6 - Posted 2014-03-31 03:53:47 »

I tried it and it didn't work.
Offline ewg

Junior Member


Medals: 7


Java games rock!


« Reply #7 - Posted 2014-03-31 07:38:24 »

You did not include the code to your Entity class, but I think it may be because you redefine these int variables in the DialogBTN class and you set them instead of setting the x,y,w,and h in the Entity superclass.  So you have to remove these variables in DialogBTN and make the ones in the superclass public or protected or set the Entity fields with "super.x = ..."

public class DialogBTN extends Entity
{
   public int x, y, w, h;
Offline Rhys Campbell

Senior Newbie


Projects: 1



« Reply #8 - Posted 2014-03-31 11:51:54 »

You did not include the code to your Entity class, but I think it may be because you redefine these int variables in the DialogBTN class and you set them instead of setting the x,y,w,and h in the Entity superclass.  So you have to remove these variables in DialogBTN and make the ones in the superclass public or protected or set the Entity fields with "super.x = ..."

public class DialogBTN extends Entity
{
   public int x, y, w, h;

I just found out what was wrong. I wasn't meant to redefine those x,y,w,h variables lol. Just a silly simple mistake.
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!