473,513 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URGENT : keyevent not working!!

8 New Member
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 3841
blazedaces
284 Contributor
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
true blue
8 New Member
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 Recognized Expert MVP
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
1693
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
2201
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
1851
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
9205
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
1702
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
2943
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
2786
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
1232
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
6688
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...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.