Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  Event Listener troubles!  (Read 1715 times)
0 Members and 1 Guest are viewing this topic.
Offline gridur

Senior Newbie




Groovy


« Posted 2005-07-27 02:30:02 »

Hey!

I have some trouble getting to the event listeners in my little game, this is because of a refactoring renovation, i have managed to get the graphics part working and all, but the event listeners just dont want to talk to me.

So this is the case. I have made a main class for creating the window component, all the rendereing context and stuff is started here and everything is renderd on a Frame component.
The thing i have done is that i created a class for the editor, to this i send the Frame, Graphics2D and BufferStrategy that i have already made in the main class so that all can work as it should in the editor class.
In the Editor class i have a render class and event listeners (MouseListener and MouseMotionListener).
The things that works nice is the Graphics, all stuff renders as it should, but i just cant get them listeners to work, i have specified them as follows:

      editFrame.addMouseMotionListener(this);
      editFrame.addMouseListener(this);

Where editFrame is the Frame component that i've sent from the main class.

So the big Q is: How do i make my listeners work in the editor class, or can they work at all? or do i have to make a whole new Frame object and a separate Window component to make it all work?

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline gridur

Senior Newbie




Groovy


« Reply #1 - Posted 2005-07-27 09:41:46 »

Now i have tryed with a nested class that extends MouseAdapter, but it still wont work, im getting loco by this problem.
Feels like i have found the brick wall and cant get past hehe, so i really appriciate all the help i can get on this problem, pleeeeaase Smiley

Very well, all tips and suggestions are much appriciated.

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline kevglass

JGO Kernel


Medals: 123
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2005-07-27 09:45:56 »

If you could post the section of code in question we might be able to spot where you're going wrong, but the description you gave sounds like you're doing the right things.

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gridur

Senior Newbie




Groovy


« Reply #3 - Posted 2005-07-27 10:59:05 »

Well, i belive that the best thing to do then is to post the 2 classes that are involved in this problem, It might be a bit hard to find the Editor call i all the event listeners in main class, i havent deleted them yet, but i will do so if i can solve this problem.

The call anyway is:

new Editor(mainFrame, g, bufferStrategy);

In this event call i also pause the main loop for the PEJava class so that the Editor loop takes over and the Graphics2D just calls trough the Editor class...

Well, check the code and see if you can find the problems, real nice of you =)

The files:

PEJava.java - Main class http://www.home.no/kutulunadir/Java/PEJava.java
Editor.java - Editor class http://www.home.no/kutulunadir/Java/Editor.java

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline kevglass

JGO Kernel


Medals: 123
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #4 - Posted 2005-07-27 11:20:08 »

Thats some "interesting" code Smiley

I think the reason you're not getting events in your Editor class is because you're starving the event thread. Your editor loop is very type and doesn't allow any time for events to be delivered. In this bit

1  
2  
3  
4  
5  
6  
7  
8  
9  
while(editor)
      {
         Graphics2D g = (Graphics2D)b.getDrawGraphics();
         
         this.renderEditor(g);
         
         g.dispose();
         b.show();
      }


Try adding a sleep or something to prevent the thread just shooting off. The AWT events are delivered by a seperate thread running the background which might be getting no processor time because your game loop is so tight.

Kev

PS. Looking at the code I think you need to rethink your structure a bit otherwise you're going to end up with a maintainence nightmare.

Offline gridur

Senior Newbie




Groovy


« Reply #5 - Posted 2005-07-27 11:42:37 »

Now i tryied to add a sleep in the while loop, still no reaction from the events =(
The Editor loop looks like this at the moment:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
      while(editor)
      {
         try
         {
            Thread.sleep(10);  // This should be replaced with proper frame rate limiting code
        }
         catch( InterruptedException e ) {}
         Graphics2D g = (Graphics2D)b.getDrawGraphics();
         
         this.renderEditor(g);
         
         g.dispose();
         b.show();
      }


I am aware of the structural problems at the moment, thats why i want to move the editor to a seperate class so that the main class wont be so chaotic hehe, im going to fix this asap, got alot of struction work to do from here before i can start programming the game again, irl im accually a gfx artist for our game company so this is a hobbie thing, programming games and stuff =)

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline kevglass

JGO Kernel


Medals: 123
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2005-07-27 11:46:26 »

Hmm.. ok, I'd try building this up a piece at a time next then. Take the game loop out, take most of the functionality out.. leave it with add mouse listener, and a System.out.println() statement in each of the event listener methods. If that works, start adding stuff back in a piece of time until something breaks it.

Looking throuhg the code (for a short spell), there didn't seem to be anything obviously wrong.

Sorry I can't be of more help,

Kev

Offline gridur

Senior Newbie




Groovy


« Reply #7 - Posted 2005-07-27 12:12:09 »

hehe i was afraid you'd say that, very well, i'll do it the hard way then, im going to completely remove all the eventlisteners from the main class and put them in thiere reletive classes (Menu, Editor and Game) so i'll start with something easy, like the Menu thingie, and go through the code like a weazel Tongue

Anyway, tnx for all the help, and i like your SpaceHulk project, looks promesing, hope you get all sorted up with the graphical stuffs!

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline gridur

Senior Newbie




Groovy


« Reply #8 - Posted 2005-07-27 12:41:30 »

Now i have completely removed all the listeners from the main class and added the ones that was needed in the menu system to the menu class, works like a clock, so i think this was a good thing to do, so now i just have to controll the Editor from the menu class and make the listeners work just like in the menu class.

Its great when stuff works out in the end =)

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
Offline kevglass

JGO Kernel


Medals: 123
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #9 - Posted 2005-07-27 12:43:25 »

Nice work... let us see when you're done Smiley

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gridur

Senior Newbie




Groovy


« Reply #10 - Posted 2005-07-27 12:57:15 »

I guess i can post the complete source when my cleaning session is done, by fixing this little thingie it mostly rough work to be done, refactoring and cleaning up in the code, so i'll post the project in the source code section in a couple of days! =)

ps. Now the event listeners in the Editor works to, what i had to do is to kill the active loop with eventlistener, then make a call for the Editor in the end of the active loop, to make sure that the menu loop does not conflict with the Editor loop like this:

1  
2  
3  
4  
5  
            
else if(e.getX() > 320 && e.getX() < 480 && e.getY() > 360 && e.getY() < 420)
{
   meny = false;
}


And the loop looks like this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
      while(meny)
      {
         try
         {
            Thread.sleep(10);  // This should be replaced with proper frame rate limiting code
        }
         catch( InterruptedException e ) {}
         Graphics2D g = (Graphics2D)b.getDrawGraphics();
         
         this.renderMeny(g);
         
         g.dispose();
         b.show();
         if(!meny)
            new Editor(menuFrame, g, b);
      }


Thnx again for the help, it was good to hear that there were no faults in the code, but more logical errors, well, sometimes you just have to figure out wierd ideas to solve things hehe

// Gridur<br />--------------------------------------<br />Spell of Play Studios<br />http://www.spellofplay.com<br /><br />Download and test the open Beta of Time Breaker (3D Arkanoid) and comment on our forum!<br />---------------------------------
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.

CogWheelz (12 views)
2014-08-01 22:53:16

CogWheelz (14 views)
2014-08-01 22:51:43

CopyableCougar4 (15 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

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

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

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

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

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