KeyEvent cannot be resolved to a type是什么原因啊

package sb1;

import java.awt.Graphics;

import java.awt.event.KeyListener;

import javax.swing.JPanel;

import java.awt.*;

import javax.swing.*;

public class SB0 extends JPanel implements KeyListener{

 int lenght;

 int[] she_x=new int[500];

 int[] she_y=new int[500];

 String fx;

 boolean start=false;

public SB0() {

 init();

}

public void init() {

  lenght=3;

  fx="r";

  she_x[0]=100;she_y[0]=100;

  she_x[1]=75;she_y[1]=100;

  she_x[2]=50;she_y[2]=100;

  she_x[3]=25;she_y[3]=100;

}

 protected void paintComponent(Graphics g) {

 super.paintComponent(g);

 int a=1;

 new ImageIcon("jpg/狗头_900_100.jpg").paintIcon(this,g,a,1);

 g.fillRect(25,75, 850,600);

 if(fx.equals("r")) {

  new ImageIcon("jpg/right.png").paintIcon(this,g ,she_x[0]+25 ,she_y[0] );

 }else if(fx.equals("1")) {

  new ImageIcon("jpg/left.png").paintIcon(this,g ,she_x[0]+25 ,she_y[0] );

 }else if(fx.equals("u")) {

  new ImageIcon("jpg/up.png").paintIcon(this,g ,she_x[0]+25 ,she_y[0] );

 

 }else if(fx.equals("d")) {

  new ImageIcon("jpg/down.png").paintIcon(this,g ,she_x[0]+25 ,she_y[0] );

 

 }

 for(int i=1;i<=lenght;i++) {

  new ImageIcon("jpg/boyd.png").paintIcon(this,g ,she_x[i] ,she_y[i] );

 }

 if(start==false) {

  g.setColor(Color.white);

  g.setFont(new Font("微软雅黑",Font.BOLD,40));

  g.drawString("按下夏福特开始游戏", 300, 300);

 }

 }

 public void keyPressed(KeyEvent e) {

    

  }

}

KeyListener 接口里面没有keyPressed方法,只有keyTyped和keyReleased,你是要监听按键还是按钮

应该是你类型没写对 不存在这样的KeyEvent

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632