Solved

Applet : press any key to continue

Posted on 2003-10-22
6
351 Views
Last Modified: 2010-03-31
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 !

0
Comment
Question by:everfly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Accepted Solution

by:
savalou earned 20 total points
ID: 9599148
Why can't you include the file$1.class in your signed jar?

The file$1.class is generated because you're using an anonymous subclass of KeyAdaptor (new KeyAdaptor() {//this is an anonymous class...}).  To get around this you can write your own class like MyKeyAdaptor.java in which you extend KeyAdaptor.
0
 

Author Comment

by:everfly
ID: 9599535
Thanks savalou. Right, I included the file$1.class in my signed jar but adding "this.addKeyListener(new KeyAdapter() {public void KeyPressed(KeyEvent e) {}});" doesn't wait for me to press any key.
And also, isn't there a easier way to perfom this ?
Thanks.
0
 
LVL 92

Expert Comment

by:objects
ID: 10194156
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
0
 

Expert Comment

by:Bobby_Hirst
ID: 10220786
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
0
 

Expert Comment

by:Bobby_Hirst
ID: 10220797
Sorry, read 'should not' in the last sentence
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error in @AspectJ Based AOP with Spring 2 24
ejb message driven bean mdb creation steps 2 36
Selenium docs api java index 3 69
jmeter usage 4 38
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question