Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Creating a basic key buffer  (Read 1380 times)
0 Members and 1 Guest are viewing this topic.
Offline Porlus

Junior Member





« Posted 2012-07-01 21:46:34 »

Hi all, I've made a really basic keyboard class that holds the states of each key, which are for me (pressed and not pressed). I've made the half of the class logs key presses and allows you to check whether a specific key is currently pressed. I'm just wondering how I would go about implementing a key buffer, so that I can allow the user to, for example, type characters and have the text be inserted somewhere within the program. Could anyone explain to me how this would typically be done? Any tutorials anyone has would be great too.

Thanks in advance,

Paul Smiley
Offline aazimon
« Reply #1 - Posted 2012-07-02 16:39:48 »

Porlus,
  I'm not fully understanding what you are trying to do. Are you want to set up a system that stores which keys are pressed and which ones are not, then the remaining program will access that system to determine if a particular key is pressed or not?
   If so, you will want to have your program "hook into" the key system, so that it can poll a key's state. For example, a sprite class would have a reference to the key system (or just the keys it's interested in), then it will query the reference for the key's current state. Similar to the ActionListeners in Swing.
Let me know if that's what you're looking for.
Aazimon Smiley
Offline pjt33
« Reply #2 - Posted 2012-07-02 21:37:10 »

As always, the answer is "It depends".

The two critical questions would be 1) where do you want to trade off between OO and to-the-metal. (java.util.List<Character> or a circular buffer?); 2) what do you want to do about key repeats?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-07-03 01:41:44 »

Where would the text be written? Either use a JOptionPane for input or create your own TextField GUI widget.

Offline Porlus

Junior Member





« Reply #4 - Posted 2012-07-03 01:50:40 »

Ah, I've worked out a way to do it. For anyone who's interested I just made an ArrayList of KeyEvents and added keys to it as they're pressed. Then I loop through this ArrayList and add them to whatever other part of the application, then at the end of that tick in the game loop I clear the ArrayList. Smiley
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.

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

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

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

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

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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!