Article View: borland.public.jbuilder.java.api
Article #3177Help: No respond to my Keypress Action
From: liubin
Date: Fri, 10 Apr 1998 00:00
Date: Fri, 10 Apr 1998 00:00
45 lines
1658 bytes
1658 bytes
Hi, everyone,
I met a problem with keypress respond. See the code below:
public class mainFrame extends Frame {
...
public mainFrame() {//constructor;
...
//{{REGISTER_LISTENERS
SymKey aSymKey = new SymKey();
this.addKeyListener(aSymKey);
//}}
}
...
class SymKey extends java.awt.event.KeyAdapter
{
public void keyPressed(java.awt.event.KeyEvent event)
{
Object object = event.getSource();
if (object == mainFrame.this)
mainFrame_KeyPress(event);
}
}
void mainFrame_KeyPress(java.awt.event.KeyEvent event)
{
// to do: code goes here.
int nKeyCode = event.getKeyCode();
String sKeyText = event.getKeyText(nKeyCode);
System.out.println("Key Press : " + sKeyText);
}
}
// end of All.
Then, I press some key, just 'A','B', 'C', but there is no respond at
all !
No output at all !
Are there some mistakes in my code ? If the class Frame and its
subclass can not respond to key actions ?
Somebody help !
Thanks.
Technical Details
Message-ID:
<352D80F1.E8F9B206@sky.whnet.edu.cn>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,45d5dc9d1c5edba9,start X-Google-Attributes: gid1089d0,public From: liubin <liubin@sky.whnet.edu.cn> Subject: Help: No respond to my Keypress Action Date: 1998/04/10 Message-ID: <352D80F1.E8F9B206@sky.whnet.edu.cn> X-Deja-AN: 342604308 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.api