Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

problem with keyevent

  Asked By: Anpu    Date: Jun 29    Category: Java    Views: 376
  

i have this application,using mouselistener and keylistener.it works
fine on version 1.3 but when i use it on 1.4,the keylistener wont
work.i am wondering why,can anyone help me with this?

here is my codes

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

public class WindowTest
{
public static void main(String args[])
{
new WindowTestWindow();
}
}

class WindowTestWindow extends JWindow
{
WindowTestWindow()
{
super();
// Components should be added to the container's
content pane
Container cp = getContentPane();
addKeyListener(new KeyAdapter() //for key press
{
public void keyTyped(KeyEvent event)
{
char key = event.getKeyChar();
if (Character.isLetterOrDigit(key))
{
dispose();
System.exit(0);
}
}
public void keyPressed(KeyEvent event){}

public void keyReleased(KeyEvent event){}


});

addMouseListener(new MouseAdapter() //for mouse click
{
public void mouseEntered(MouseEvent event){}

public void mouseExited(MouseEvent event){}

public void mouseClicked(MouseEvent event)
{

System.exit(0);

}

public void mousePressed(MouseEvent event){}

public void mouseReleased(MouseEvent event){}

});


//get screen size
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();

// Show the frame according to the user's window size
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setSize(screenWidth, screenHeight);

//set background color black
cp.setBackground(Color.black);

// Show the frame
setVisible(true);
requestFocus();
}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on problem with keyevent Or get search suggestion and latest updates.




Tagged: