Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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  
  Where to add keylistener with FullScreen?  (Read 2975 times)
0 Members and 1 Guest are viewing this topic.
Offline AJim

Senior Newbie




Java games rock!


« Posted 2004-02-08 11:52:34 »

Hello all, i went through the wiki for some help on fullscreen and keyboard input. I looked at the code and tested it out.
Now that i've somewhat understood how fullscreen works, thanks to the wonderful and clear comments made, i began tinkering around the code. (IE Displaying random objects, pictures, etc...) But the thing that I can't seem to get right is the keylistener.

I'm also using my Deitel java book for reference, but everything they do requires swing and they added "addKeyListener(this)" within the constructor of the class.
I looked through the fullscreen code and saw that well although some of it is similar to swing, i don't think it really uses it. (I'm a newbie to java ). I was wondering where i Should implement "addKeyListener(this)" because so far i can't get keyboard input to work and its frustrating me !!

Thanks!
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2004-02-08 12:42:17 »

You can probably add it to the frame you used to create the fullscreen exclusive mode?

Kev

Offline AJim

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-02-08 20:02:38 »

do you mean replace 'this' with mainFrame? or use "addKeyListener(this)" when i construct a fullscreen window?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2004-02-09 04:36:03 »

Yep, it might work Smiley

Kev

Offline AJim

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-02-13 11:36:10 »

cough..which one please..? Am still stuck
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2004-02-13 11:42:08 »

Damn, I'm sorry.. didn't make that too clear,

You want to add the KeyListener to the Frame. So if your frames is called "mainFrame" then at some point you've got to do mainFrame.addKeyListener(myListener).

Something like (excuse pseduo code, I'm not a decent pooter right now)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public class MyKeyListener implements KeyListener {
    public void keyPressed(KeyEvent e) {
       // do what you want here
   }
 
    public void keyReleased(KeyEvent e) {}

    public void keyTyped(KeyEvent e) {}
}

public class MyFullScreenFrame extends Frame { // or extends JFrame
   public MyFullScreenFrame() {
         super("Demo 1");

         // make this window fullscreen

         addKeyListener(new MyKeyListener());
    }
}


Sorry if its not dead on.. shout if you need more help...

Kev

Offline AJim

Senior Newbie




Java games rock!


« Reply #6 - Posted 2004-02-16 14:36:40 »

Hum..wow..
all i had to do was type "mainFrame.addKeyListener(this);"
but i dont' understand why when i typed "addKeyListener(this);", it did not accomplish the same thing? Perhaps the compiler doesn't know what to add to exactly ?

Thanks very much kev.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #7 - Posted 2004-02-16 20:42:53 »

There is a lot more to it than 'typing'  ...

Where did you put the code.  Obviously not in a member function of mainFrame.

Offline AJim

Senior Newbie




Java games rock!


« Reply #8 - Posted 2004-02-18 00:08:21 »

Well before I tried adding "addKeyListener(this)" to area where we create the frame. When i added "mainFrame.addKeyListener(this)" to the part I initialized other objects which is also after the creation of the mainFrame, my key listener started working.
Also i was wondering:
When i tried the keyboard input from the wiki, my vk_arrow keys do not work? Left, Right, Down, Up generate the same key instance and i'm not sure why. VK_ESCAPE works perfectly, but its these virtual arrow keys that make my program annoying. Sigh..
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #9 - Posted 2004-02-18 00:28:29 »

I'm not a big fan of Dietel; I hate their books.  There are about two basic ways to handle events in swing; implementing the listener intreface or using the Component method enableEvents() + process_Event().  

EventListeners in swing is a pretty big topic. It would be a really good idea to read over the swing tutorial in the java tute; particularly this part:

http://java.sun.com/docs/books/tutorial/uiswing/events/index.html

Lots of examples to look at and play with.
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.

radar3301 (10 views)
2014-09-21 23:33:17

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (46 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24: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!