Yefly开森 2022-01-28 16:53 采纳率: 0%
浏览 65
已结题

我想问一下这为什么会报错,用的eclipse

package cn.sxt.game;

import javax.swing.JFrame;

public class MyGameFrame extends JFrame{

//初始化窗口
public void launchFrame() {
    this.setTitle("飞机游戏作品");
    this.setVisible(true);//窗口可见
    this.setSize(500,500);//设置窗口大小
    this.setLocation(300,300);
    
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            System.exit(0);
        }    
    });
}

public static void main(String[] args) {
    MyGameFrame f = new MyGameFrame();
    f.launchFrame();
}

}

#############################################################
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addWindowListener(WindowListener) in the type Window is not applicable for the arguments (new WindowAdapter(){})
WindowAdapter cannot be resolved to a type
WindowEvent cannot be resolved to a type

at cn.sxt.game.MyGameFrame.launchFrame(MyGameFrame.java:20)
at cn.sxt.game.MyGameFrame.main(MyGameFrame.java:33)
  • 写回答

1条回答 默认 最新

  • 若有所思_若有所悟 2022-01-28 17:10
    关注

    报错日志的行数和代码的行数对不上,估计修改完没有保存。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 1月28日
  • 创建了问题 1月28日

悬赏问题

  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 VB.NET如何绘制倾斜的椭圆
  • ¥15 arbotix没有/cmd_vel话题
  • ¥15 odoo17的分包重新供应路线如何设置?可从销售订单中实时直接触发采购订单或相关单据
  • ¥15 用C语言怎么判断字符串的输入是否符合设定?