keylistener problem with applet

Discussion in 'Java' started by biner.sebastien@ouranos.ca, Jan 3, 2006.

  1. Guest

    Hello,

    I am working on a little applet game. The applet reads the keys with
    a keylistener.

    I develop the Applet on Linux using appletviewer and/or Eclipse
    (which uses appletviewer I think). When I start the applet this way, it
    does not register the key I press. But if open the applet using Firefox
    it works. I also tested the Applet with appletviewer on Windows XP and
    Mac OsX10.3 and it works.

    Has anybody experienced similar problem? Any hint of a solution? If
    useful, I use Xandros linux version 3.

    I put the code for the Applet at the end of this email if it may help
    you help me.

    Thanks for any help.

    Sebastien.

    *** start of code ***

    import javax.swing.* ;
    import java.awt.* ;


    public class Ai1 extends JApplet {

    PControle pcontrole ;
    PDessin pdessin ;
    PJeux pjeux ;
    Container cp ;
    boolean focus ;


    public Vehicule1 v1 = new Vehicule1() ;

    // methode init
    public void init() {

    // on met le focus sur l'applet et on ecoute le clavier
    this.setFocusable(true) ;
    this.requestFocus() ;
    this.addKeyListener(new ecouteClavier(v1)) ;

    // initialisation des panel
    pdessin = new PDessin(Utilitaires.niPDessin,Utilitaires.njPDessin,v1)
    ;
    pcontrole = new PControle() ;
    pjeux = new PJeux(v1) ;

    // ajout de panel a l'applet
    cp=getContentPane() ;
    cp.setLayout(new BoxLayout(cp,BoxLayout.X_AXIS)) ;
    //cp.add(pdessin) ;
    cp.add(pjeux) ;
    cp.add(pcontrole) ;



    } // fin init
    } //fin Ai1
    , Jan 3, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. apchar
    Replies:
    3
    Views:
    1,826
    Andrew Hobbs
    Feb 3, 2004
  2. JariTapio

    KeyListener vs. Runnable ???

    JariTapio, Mar 25, 2005, in forum: Java
    Replies:
    2
    Views:
    714
  3. Max

    JWindow KeyListener

    Max, Oct 29, 2005, in forum: Java
    Replies:
    4
    Views:
    3,759
  4. Luc The Perverse

    KeyListener

    Luc The Perverse, Nov 12, 2005, in forum: Java
    Replies:
    2
    Views:
    783
    Luc The Perverse
    Nov 12, 2005
  5. phil89
    Replies:
    25
    Views:
    1,098
    John B. Matthews
    Jul 6, 2008
Loading...

Share This Page