everfly
asked on
Applet : press any key to continue
Hi experts,
I have written an applet that processes some datas, however, at one point, I need the user to press any key (or the enter key) to continue.
This is keyevent is not linked to any object like a button. I tried something like :
this.addKeyListener(new KeyAdapter() {
public void KeyPressed(KeyEvent e) {
}
});
but this produce an extra file$1.class that bothers me (it needs to become a signed jar).
I tried playing with something like : if ( ev.id == Event.KEY_PRESS ) with no success.
I'm sure there's a simple way to write in an applet something similar to : while ((ch = (char)System.in.read()) !=...).
Thanks experts for your answer !
I have written an applet that processes some datas, however, at one point, I need the user to press any key (or the enter key) to continue.
This is keyevent is not linked to any object like a button. I tried something like :
this.addKeyListener(new KeyAdapter() {
public void KeyPressed(KeyEvent e) {
}
});
but this produce an extra file$1.class that bothers me (it needs to become a signed jar).
I tried playing with something like : if ( ev.id == Event.KEY_PRESS ) with no success.
I'm sure there's a simple way to write in an applet something similar to : while ((ch = (char)System.in.read()) !=...).
Thanks experts for your answer !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept savalou's comment as answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
objects
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Accept savalou's comment as answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
objects
EE Cleanup Volunteer
How about this:
this.addKeyListener(new KeyAdapter() {
public void KeyPressed(KeyEvent e) {
continue=true;
}
});"
//add this bit where you want execution to stop:
boolean continue=false;
while (!continue) {} //this will loop, until the KeyEvent allows the
//execution to continue.
I think that should solve it... The thing that you hadn't taken into account is that KeyListener runs in parallel with your code listening for Events, and if no event is assigned to it, nothing will happen to your main code's execution. As for the extra class file, I think it's unavoidable but should cause any problems when you create a signed jar
this.addKeyListener(new KeyAdapter() {
public void KeyPressed(KeyEvent e) {
continue=true;
}
});"
//add this bit where you want execution to stop:
boolean continue=false;
while (!continue) {} //this will loop, until the KeyEvent allows the
//execution to continue.
I think that should solve it... The thing that you hadn't taken into account is that KeyListener runs in parallel with your code listening for Events, and if no event is assigned to it, nothing will happen to your main code's execution. As for the extra class file, I think it's unavoidable but should cause any problems when you create a signed jar
Sorry, read 'should not' in the last sentence
ASKER
And also, isn't there a easier way to perfom this ?
Thanks.