Not working key listene. What's wrong?

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
public class one1 {
 public static void main(String[] args) {
 myFrame frame=new myFrame();
}

}
class myFrame extends JFrame {
 public myFrame() {
 Dimension dm=Toolkit.getDefaultToolkit().getScreenSize();

 int w1=dm.width;
 int h1=dm.height;

 int w2=w1/2-NW1/4;
 int h2=h1/2-h1/4;

 int w3=w1/2;
 int h3=h1/2;

 myPanel p=new myPanel();
 Container cont=getContentPane();
cont.add(np);
setResizable(false);
setBounds(w2,h2,w3,h3);
setSize(w3,h3);
 setBackground(new Color(128,128,128));
setOpacity(1f);
setVisible(true);
}
}
class myPanel extends JPanel {
 private class myKey implements KeyListener {
 public void keyPressed(KeyEvent e) {
 int key_=e.getKeyCode();
if(key_==27)System.exit(0);
}
 public void keyReleased(KeyEvent e) {
}
 public void keyTyped(KeyEvent e) {
}
}
}
March 25th 20 at 13:28
0 answer

Find more questions by tags Java