473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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.setText("Are you sure (y/n):");
if (KeyEvent.getKeyChar() == '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 1688
"Lannsjö" <no*****@tosay.com> wrote in message
news:6J********************@newsc.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.setText("Are you sure (y/n):");
if (KeyEvent.getKeyChar() == '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
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...
3
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
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...
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...
1
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 ...
9
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....
3
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...

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.