Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (624)
Games in Android Showcase (176)
games submitted by our members
Games in WIP (676)
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  
  Adding a KeyListener to  (Read 1335 times)
0 Members and 1 Guest are viewing this topic.
Offline stroh

Senior Newbie

Java games rock!

« Posted 2004-11-27 23:51:02 »

Hello. I am currently trying to take Sun's file and work it into a black hole simulator for a college project. I am trying to setup my basic geometry and am currently trying to add a KeyListener whereby I can use keyboard commands (the arrows in particular) to rotate the view around my ellipsoids. Also note that I am a newbie.

The KeyListener is added to my canvas as it is the only think I could find that would allow a KeyListener to be added to. I then read online that it would be good to create a switch to tell the program when to process the rotations however I can't get it to work. It simply doesn't do anything.

Thus far I have tried adding my transforms to the BranchGroup createSceneGraph but that didn't work. Recently I tried placing the rotation transforms in their own BranchGroup and adding the other transforms for the ellispoids as a child under that BranchGroup. But this also has not worked. I'm fairly certain that my KeyListener is working.

Does anybody have any suggestions on the proper way to pull this off?

I have posted my code at since it is too long to post in this forum.

Much thanks in advance!
Offline CaptainJester

JGO Knight

Medals: 12
Projects: 2
Exp: 14 years

Make it work; make it better.

« Reply #1 - Posted 2004-11-28 01:08:18 »

Where you have:

c.addKeyListener( this );  


addKeyListener( this );  

Offline stroh

Senior Newbie

Java games rock!

« Reply #2 - Posted 2004-11-28 02:22:13 »

No, that doesn't help.

The KeyListener works and does read my keys but it is the link from my keys changing my rotation variables and the transforms is where I'm having problems.

You can pretty much skip the first branchgroup in my code. That just sets up my basic geometry. I have my transforms in that portion where you found the c.addKeyListener(this) and for some reason they aren't working.

Thanks for the suggestion though, however, without that "c." portion my KeyListener doesn't even work.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dranonymous

Junior Devvie

Hoping to become a Java Titan someday!

« Reply #3 - Posted 2004-11-30 00:54:30 »

I couldn't get it to run without changing 2 lines.  I had to add a call to getContentPane(), otherwise it threw an exception.  Lines 437 and 456.

What should you see when things are working correctly?

Dr. A>
Offline stroh

Senior Newbie

Java games rock!

« Reply #4 - Posted 2004-11-30 03:18:25 »

Try downloading the file again. It should work without those calls (at least it seems to for me using netBeans). If you do need those calls could you specify how you added those to the lines?

Once it runs it should show a couple of nested ellipsoids with a smaller sphere in the center of them and another larger sphere outside of them. I also have a JPanel added to the bottom of the applet but haven't had time to work on it yet. I want to first get this keyboard command interface working before moving on to that.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

KaiHH (15 views)
2015-10-11 14:10:14

KaiHH (15 views)
2015-10-11 13:26:18

BurntPizza (44 views)
2015-10-08 03:11:46

BurntPizza (21 views)
2015-10-08 00:30:40

BurntPizza (26 views)
2015-10-07 17:15:53

BurntPizza (42 views)
2015-10-07 02:11:23

KaiHH (47 views)
2015-10-06 20:22:20

KaiHH (21 views)
2015-10-06 19:41:59

BurntPizza (38 views)
2015-10-06 19:04:48

basil_ (52 views)
2015-09-30 17:04:40
Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

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