我正在尝试制作一个简单的 Java 程序,但我无法从中获得任何输入。任何人都可以提出解决方案吗?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
class KeyIns extends JFrame implements KeyListener {
public void KeyIns(){
addKeyListener(this); //==> this is why ....
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("1");
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("2");
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("2");
}
}
public class Hello {
public static void main(String[] args){
KeyIns inkey = new KeyIns();
inkey.setSize(368, 300);
inkey.setLocation(250, 250);
inkey.setVisible(true);
}
}