Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (616)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
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  
  problems with listeners  (Read 1263 times)
0 Members and 1 Guest are viewing this topic.
Offline Kova

Senior Devvie

« Posted 2005-11-10 23:02:49 »

I'm writing a simple soccer game. I have a JFrame as main container for stuff and a JPanel object in seperate thread for animation. Problem is when I try to build a proper start menu. JPanel has mouse listeners. The problem is when I add listeners to JFrame also and put a code to start a game when rectangle over start button is clicked. If JPanel object is created first  (even if I don't need it right away) then JFrame mouse events don't happen, well actually JPanel's listener methods have still control of it even if I didn't added it yet. So I don't get it, there can be only one listener? For easier programming I want to divide code that needs to be executed into their own classes, trying to avoid to put all listener code to JFrame (main class). Thanks for the help.
Offline Jeff

JGO Coder

Got any cats?

« Reply #1 - Posted 2005-11-13 01:58:21 »

You are experiencing some of the resons why serious game prgrammers dont build ontop of widget systems.

They write their own menuing ontop of the framebuffer or 3D API/

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #2 - Posted 2005-11-13 02:09:56 »

1. Don't use threads for animation
2. Don't use multiple panels and/or frames
3. Don't use multiple mouse listeners

For your own sanity, have a single method of retriving the state of the input (such as a single mouse listener) and pipe all of your input though a central point. Distribute to the various sections of your game as required.

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Devvie

« Reply #3 - Posted 2005-11-13 15:26:49 »

ok tnx, but how should I do it then? I'm actually reading Killer Gamer Programming in Java, publisher O'Reilly. There this methods are used (except listeners). I would gladly do it any other, better way if I know about it. OK I will use central input and pass it to the needed parts of game, hopefully that will solve the problem. Tnx again.
Offline Jeff

JGO Coder

Got any cats?

« Reply #4 - Posted 2005-11-13 21:52:28 »

Most serious games go directly to the graphcis hardware to draw everything and build upon that.

There are 3 good paths today for that:  JOGL and LWJGL (used for 3D but you can also do 2D with them.  Cas has done some nice LWJGL based 2D games you can see at Puppy Games, Kev has one at his site too) and the BufferStrategy system in AWT (for 2D games.  I did an isometric exampel awhile back called Scroller I'm going to try to get into the projects this week.  There ar other examples around too, I think Kev did one this way as well, for instance.)

In terms of input, they read the controllers directly by polling.  JInput allows you to do that.  LWJGL has ist own API (but uses JInput uderneath.)  Menus are done wth your own logic.  You put a menu graophic on the screen.  When the suer clicks, you get the location of the click and compare it to where the active parts of your gaphic are and react as necessary.

ALL of this is done once per frame ina  tight loop, usually called the "game loop."  Any of the example games I mentioned will be based around a game-loop.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Offline Kova

Senior Devvie

« Reply #5 - Posted 2005-11-14 11:25:06 »

OK tnx for the info.  Wink
About start menu... isn't it better to just draw once the menu and then act upon click's location, then puting him in game loop? This way it uses much less cpu's time. Maybe if you have animated start menu you might do that, but I'm working only with few pictures and am long way from fancy animated menus   Roll Eyes
Offline Jeff

JGO Coder

Got any cats?

« Reply #6 - Posted 2005-11-15 03:59:37 »


in many games even the cursor is game-loop animation....

Certainly if you want to have visual resposne to user event your going to need to do some kind of basic blt based animation eventually...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Coldstream24 (16 views)
2015-09-03 00:41:28

Andrew_3ds (26 views)
2015-09-01 19:08:10

afikri (17 views)
2015-08-31 09:30:22

afikri (25 views)
2015-08-31 09:30:07

afikri (13 views)
2015-08-31 09:27:24

afikri (16 views)
2015-08-31 09:26:40

Roquen (30 views)
2015-08-29 11:30:54

GamerC4 (36 views)
2015-08-22 20:38:50

GamerC4 (33 views)
2015-08-22 20:37:18

GamerC4 (40 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 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‑
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!