By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

KeyEvent novice question

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.