gpt4 book ai didi

java - 框架监听器Java

转载 作者:行者123 更新时间:2023-12-02 09:02:36 25 4
gpt4 key购买 nike

为什么当我去调用 windowsClosing 方法 (WindowEvent e) 时,我收到“java: 找不到符号”错误?

import java.awt.*;
import java.awt.event.*;

public class Finestra implements WindowListener {

public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
}

public void windowClosed(WindowEvent e) {
System.exit(0);
}

public void windowOpened(WindowEvent e) {
}

public void windowIconified(WindowEvent e) {
}

public void windowDeiconified(WindowEvent e) {
}

public void windowActivated(WindowEvent e) {
}

public void windowDeactivated(WindowEvent e) {
}
}

主类:

import java.awt.*;
import java.awt.event.*;

public class main {
public static void main(String args[]) {
Grafica g = new Grafica();
Finestra f1 = new Finestra();
f1.windowClosing(WindowEvent e);
}
}

错误由main在执行时给出到调用WindowsClosing方法的行

最佳答案

我想这会对你有帮助..Finestra.java

import java.awt.*;
import java.awt.event.*;

public class Finestra extends Frame implements WindowListener {

Finestra(){
addWindowListener(this);

setSize(400,400);
setLayout(null);
setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.out.println("closing");
e.getWindow().dispose();
}

public void windowClosed(WindowEvent e) {
System.exit(0);
}

public void windowOpened(WindowEvent e) {
System.out.println("hello");
}

public void windowIconified(WindowEvent e) {
}

public void windowDeiconified(WindowEvent e) {
}

public void windowActivated(WindowEvent e) {
}

public void windowDeactivated(WindowEvent e) {
}

}

Main.java

public class Main {
public static void main(String args[]) {
new Finestra();

}

}

我不明白你使用的 Grafica 类,但如果你想将它用于框架,你可以在 Finestra 类中扩展框架! 希望对您有帮助!

关于java - 框架监听器Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60061209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com