LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2007, 12:31 PM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
java char matching


Hello all,

Im trying to write a class that will detect when I am pressing certain keys on the keyboard. I have done the easy part but now I am trying to write some thing so when i press any of the letter keys it will open a new text box so i pseudo code it would look like this:


Code:
if( char == [a-z][A-Z] )
{

     Action

}
 
Old 10-18-2007, 01:37 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

Sounds like you need a Pattern:
http://java.sun.com/j2se/1.5.0/docs/...x/Pattern.html

Dave
 
Old 10-18-2007, 01:58 PM   #3
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
You can use ASCII table (and check whether the char is > and < then specified values).
 
Old 10-18-2007, 02:08 PM   #4
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Quote:
Originally Posted by Alien_Hominid
You can use ASCII table (and check whether the char is > and < then specified values).
This, I think, is a fairly general method, but it has a weakness; ASCII table doesn't contain some characters that are used outside of English, so pressing those keys wouldn't work (it may cause funny things, because the number values for those keys are really different from those of ASCII chars). If the program never faces non-ASCII characters it's ok, but I wouldn't take chances..
 
Old 10-18-2007, 02:49 PM   #5
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
Maybe use a streamtokenizer? This can compare input (tokenizer.nextToken()) with a tokenizer. TT_WORD constant (word can be a single letter here) so you don't need to specify the range of letters yourself (although it is perfectly possible to do so in an if /else statement).
 
Old 10-18-2007, 03:05 PM   #6
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Quote:
Originally Posted by b0uncer View Post
This, I think, is a fairly general method, but it has a weakness; ASCII table doesn't contain some characters that are used outside of English, so pressing those keys wouldn't work (it may cause funny things, because the number values for those keys are really different from those of ASCII chars). If the program never faces non-ASCII characters it's ok, but I wouldn't take chances..
His pseudocode
Code:
if( char == [a-z][A-Z] )
{

     Action

}
didn't show that any special characters will be used.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java install issue - no matching plugin was found. therapist Linux - Software 1 06-15-2007 10:08 AM
Rular expression matching with java linuxmandrake Programming 2 04-13-2006 11:35 AM
Java : Just capture 1 char hunterfighter Programming 3 12-13-2005 05:41 AM
regular expresions: java: matching lines with out string zymos Programming 1 05-28-2005 09:17 AM
empty char in java nephilim Programming 13 09-24-2003 02:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration