野生的猴 2021-06-03 20:35 采纳率: 100%
浏览 150
已采纳

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) {

    

  }

}

  • 写回答

3条回答 默认 最新

  • CSDN专家-Fay 2021-06-03 20:40
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题