473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

KeyEvent novice question

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.setT ext("Are you sure (y/n):");
if (KeyEvent.getKe yChar() == 'y'){
System.exit (status);
}
}

But the compiler says:
TextEditor.java :73: non-static method getKeyChar() cannot be referenced from
a static context

What shall I do?
/M2
Jul 17 '05 #1
1 1695
"Lannsjö" <no*****@tosay. com> wrote in message
news:6J******** ************@ne wsc.telia.net.. .
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.setT ext("Are you sure (y/n):");
if (KeyEvent.getKe yChar() == 'y'){
System.exit (status);
}
}

But the compiler says:
TextEditor.java :73: non-static method getKeyChar() cannot be referenced from a static context

What shall I do?
/M2

Start here:
http://java.sun.com/docs/books/tutorial

Specifically, you'll be looking for information about event listeners here:
http://java.sun.com/docs/books/tutor...ing/index.html

Come back when you have some idea what you're doing.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2352
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code (intermediate language and so on). Is there any page on internet, which makes me clear? Thanx
3
2234
by: herrcho | last post by:
Here is the code.. #define NAME "MEGATHINK, INC" #define ADDRESS "10 Megabuck Plaza" #define PLACE "Megapolis, CA 94904" int main() { starbar(); printf("%s\n",NAME);
2
2254
by: Dmitry Sazonov | last post by:
I'm novice here and I'm sorry for stupid question. We are trying to understand web services architecture, is it better than TIBCO.Randevouz and does webservices fit our needs. I understand, I can make web servce and a client applicaiton. Client will call the service and will receive some kind of responce. But can my client applicaiton...
1
2202
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 other applications running concurrently which use the same hotkey. i want to do this because i want my app frame (a mdi frame) to accept the key...
0
1853
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 property is set to true but when i assing the "keydown" event on the user control, nothing happens. i set a breakpoint in the event method and...
2
9208
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 a number of hacks, I really want to use events, since they seem like the "right" way to do an onscreen keyboard. Just fire the key events...
1
2993
by: TwistedSpanner | last post by:
Hello all, For the record I am a complete java novice. I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows Random number, Random operator (+ or -) random number. I have written the program but cannot make the random operator work. Can anyone help? My...
9
3041
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or...
3
3846
by: true blue | last post by:
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.*;
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5218
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.