java 键盘事件未响应
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;classCaoextendsJFrame{pri...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Cao extends JFrame
{
private char keychar='A';
public Cao(){
addKeyListener(new KeyAdapter(){
public void KeyPresssed (KeyEvent e){
switch(e.getKeyCode()){
case KeyEvent.VK_UP: break;
case KeyEvent.VK_LEFT: System.out.println("cao") ; break;
case KeyEvent.VK_RIGHT:break;
default:keychar=e.getKeyChar();
}
}
});
}
public static void main(String[] args)
{
Cao k=new Cao();
k.setLocationRelativeTo(null);
k.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
k.setSize(800,850);
k.setVisible(true);
k.setFocusable(true);
}
}
望改动最小,并说明原因。 展开
import javax.swing.*;
import java.awt.event.*;
class Cao extends JFrame
{
private char keychar='A';
public Cao(){
addKeyListener(new KeyAdapter(){
public void KeyPresssed (KeyEvent e){
switch(e.getKeyCode()){
case KeyEvent.VK_UP: break;
case KeyEvent.VK_LEFT: System.out.println("cao") ; break;
case KeyEvent.VK_RIGHT:break;
default:keychar=e.getKeyChar();
}
}
});
}
public static void main(String[] args)
{
Cao k=new Cao();
k.setLocationRelativeTo(null);
k.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
k.setSize(800,850);
k.setVisible(true);
k.setFocusable(true);
}
}
望改动最小,并说明原因。 展开
展开全部
//你的方法名字写错了 多写了个s
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Cao extends JFrame {
private char keychar = 'A';
public Cao() {
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
break;
case KeyEvent.VK_LEFT:
System.out.println("cao");
break;
case KeyEvent.VK_RIGHT:
break;
default:
keychar = e.getKeyChar();
}
}
});
}
public static void main(String[] args) {
Cao k = new Cao();
k.setLocationRelativeTo(null);
k.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
k.setSize(800, 850);
k.setVisible(true);
k.setFocusable(true);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Cao extends JFrame {
private char keychar = 'A';
public Cao() {
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
break;
case KeyEvent.VK_LEFT:
System.out.println("cao");
break;
case KeyEvent.VK_RIGHT:
break;
default:
keychar = e.getKeyChar();
}
}
});
}
public static void main(String[] args) {
Cao k = new Cao();
k.setLocationRelativeTo(null);
k.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
k.setSize(800, 850);
k.setVisible(true);
k.setFocusable(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询