Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Key Listener not working in jinternalframe

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Key Listener not working in jinternalframe

    hi all

    i made a jinternalframe and registered keylistener when a key is pressed it should print the
    key code but it doesnot print the key code. please tell me what is wrong my code is given below
    ===================

    import javax.swing.*;
    import java.awt.*;
    import javax.swing.table.* ;
    import java.util.*;
    import java.sql.*;
    import java.awt.event.*;


    public class AddContractor extends JInternalFrame implements KeyListener
    {

    public AddContractor()
    {
    super("|Contractor|" , true , true , true , true);
    try{
    setSize(463 , 450);
    setLocation(260 , 140);
    jbInit();

    }catch(Exception e)
    {
    e.printStackTrace();
    }
    } //close of addproject const


    private void jbInit() throws Exception


    {


    this.getContentPane().setLayout(null);
    this.getContentPane().setBackground(new Color(71, 97, 142));
    addKeyListener(this);
    this.setVisible(true);

    }


    public void keyPressed(KeyEvent ke)
    {
    System.out.print(ke.getKeyCode());
    }

    public void keyReleased(KeyEvent kre){

    System.out.println(kre.getKeyCode() );

    }

    public void keyTyped(KeyEvent kety){

    System.out.println(kety.getKeyCode() );

    }






    }


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,104
    Thanks
    169
    Thanked 780 Times in 726 Posts
    Blog Entries
    5

    Default Re: Key Listener not working in jinternalframe

    From the code you posted and without having a self contained runnable example its debug. In many cases keyListeners do not work on components because that particular component does not have focus (eg try calling requestFocus)

Similar Threads

  1. Key listener help
    By airsim15 in forum AWT / Java Swing
    Replies: 2
    Last Post: December 13th, 2009, 02:15 PM
  2. Working with Methods
    By duckman in forum Object Oriented Programming
    Replies: 3
    Last Post: November 9th, 2009, 07:27 PM
  3. Question about JInternalFrame
    By TimW in forum AWT / Java Swing
    Replies: 0
    Last Post: November 7th, 2009, 07:31 AM
  4. Need Help Action Listener....
    By vhizent23 in forum AWT / Java Swing
    Replies: 2
    Last Post: October 9th, 2009, 01:46 PM
  5. Replies: 4
    Last Post: January 26th, 2009, 11:03 PM