×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    how to focus on my windows when add KeyListener

    Dear Sir,
    I use PersonalJava and Nokia SDK 1.1 emulator to test my program.
    First, I define a class which extends CFrame and implements CBAListener, Runnable, KeyListener.
    Second, I add Keylistener (add.KeyListener(this))in the constuctor of the class and overload the keyPressed(),keyReleased(),keyTyped().
    Result, CBAlistener works fine but Keylistener does not work, Moreover, if I use mouse the click the top of the windows of my application. the KeyListener begin to work. I think it should be something related to focus event but I dont know how to handle it.
    Please help me.
    Code related:

    public class Music extends CFrame implements Runnable, KeyListener , CBAListener
    {
    CBAHandler cba;
    public static void main( String args[] )
    {
    new Music();
    }

    public Music()
    {

    cba = new CBAHandler( this );
    cba.setText( ADD , "Add " );
    cba.setText( CLOSE , "Close" );
    cba.activate();
    addKeyListener(this);
    item.addKeyListener(this);
    add(item);/*item is a object extends Canvas*/
    show();
    }
    public void keyPressed(KeyEvent ke){....}
    public void keyReleased(KeyEvent ke){....}
    public void keyTyped(KeyEvent ke){}
    ......
    }

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    RE: how to focus on my windows when add KeyListener

    add the sentence like that in the constructor of Music
    ....
    this.requestFocus();
    ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×