Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
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 1961 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  

EgonOlsen (38 views)
2018-06-10 19:43:48

EgonOlsen (20 views)
2018-06-10 19:43:44

EgonOlsen (40 views)
2018-06-10 19:43:20

DesertCoockie (187 views)
2018-05-13 18:23:11

nelsongames (122 views)
2018-04-24 18:15:36

nelsongames (121 views)
2018-04-24 18:14:32

ivj94 (861 views)
2018-03-24 14:47:39

ivj94 (122 views)
2018-03-24 14:46:31

ivj94 (758 views)
2018-03-24 14:43:53

Solater (139 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!