472,783 Members | 1,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

URGENT : keyevent not working!!

below is a simple program to check key event ,it doesnt give any error nor an
exception at runtime plz tell where im goin wrong



code<text>


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class keys extends Applet implements KeyListener
{
Panel p;
TextField t1;
public void init()
{
setLayout(null);
setBackground(Color.black);
t1=new TextField(20);
p=new Panel();
p.setBackground(Color.black);
p.add(t1);
p.setBounds(50,50,500,100);
add(p);
p.setFocusable(true);
resize(500,500);
setVisible(true);
addKeyListener(this);
}
public void keyPressed(KeyEvent e)
{
System.out.println("KEY");
switch(e.getKeyCode())
{
case KeyEvent.VK_RIGHT :
System.out.println("KEY RIGHT");
break;
}
}
public void keyTyped(KeyEvent e)
{
System.out.println("KEY");
}
public void keyReleased(KeyEvent e)
{
System.out.println("KEY");
}
}
Jul 28 '07 #1
3 3749
blazedaces
284 100+
below is a simple program to check key event ,it doesnt give any error nor an
exception at runtime plz tell where im goin wrong
Here, have a look at java's keyListener tutorial: http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

It should cover most of your problems...

Good luck,
-blazed
Jul 28 '07 #2
Here, have a look at java's keyListener tutorial: http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

It should cover most of your problems...

Good luck,
-blazed
thanx a ton man it helped one should add requestFocus()
after addKeyListener(this);
Jul 29 '07 #3
JosAH
11,448 Expert 8TB
Why don't you simply register your keylistener to your t1 textfield?

kind regards,

Jos
Jul 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lannsjö | last post by:
Hi Im trying to learn Java and cant really figure out how to use keyEvents. I want to know if a person has pressed y or n in a method. void doCloseCommand (int status) { statusInfo.setText("Are...
1
by: ash | last post by:
hi, is there a way to register application wide hotkey in wxpython? i tried wxWindow::RegisterHotKey(). but the problem is it registers the hotkey as a system wide hotkey. this causes problems in...
0
by: ghost | last post by:
i have a main form, with user controls populating it. i'm trying to capture a keyevent for the control that's populating the form but it never fires that event. the main form's keypreview...
2
by: hans.duedal | last post by:
The Gecko DOM reference gave me the idea that an onscreen keyboard I was doing should use Key Events, so the user may for instance place a letter anywhere, and such. While this can be handled using...
10
by: sp | last post by:
The application is written in Visual Basic / .NET and working without problems under Windows XP, Windows 2000, Windows 2003 but it isn't working under Windows ME and Windows 98 - the computer...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
1
twitch3729
by: twitch3729 | last post by:
Basicaly, I have a frame with only a Canvas on it and a KeyListener. For some reason the keyListener stops registering my keys as soon as I have moved the Window from its starting position. I have...
0
by: DosFreak | last post by:
#define SUBMODEL 1 #include "mydef.h" #include "wscreen.h" #define RIGHTSHIFT 0x0001 #define LEFTSHIFT 0x0002 #define CONTROL 0x0004 #define ALT 0x0008...
2
by: xirowei | last post by:
Dear All, I had google for example how to use java.awt.Robot class. I also read Java Document regarding of awt.Robot class. When I test below code, I get error message "cannot find symbol method...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.