Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 1041 times)
0 Members and 1 Guest are viewing this topic.
Offline Kova

Senior Member





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

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

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Orangy Tang

JGO Kernel


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

[ TriangularPixels.com - 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 Member





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

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Kova

Senior Member





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

Well..

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!

http://wiki.java.net/bin/view/Games/JeffFAQ
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.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

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

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

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

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

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

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

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

BurntPizza (36 views)
2014-08-08 02:01:56
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!