gpt4 book ai didi

java - 类型 AbstractButton 中的方法 addActionListener(ActionListener) 不适用于参数 (Object)

转载 作者:行者123 更新时间:2023-11-30 08:24:03 27 4
gpt4 key购买 nike

package in.ac.iitb.cfilt.hwnbrowser;

import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;


public class WordListBox extends JPanel
implements ActionListener, WindowListener
{

public static void showList(String type, String list[], String labelText, String title)
{
frame = new JFrame(title);
frame.setDefaultCloseOperation(2);
JComponent newContentPane = new WordListBox(type, list, labelText);
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.addWindowListener(new Object(type)
class _anm1 {}

);
frame.pack();
frame.setVisible(true);
}

public void windowOpened(WindowEvent windowevent)
{
}

public void windowClosing(WindowEvent windowevent)
{
}

public void windowIconified(WindowEvent windowevent)
{
}

public void windowDeiconified(WindowEvent windowevent)
{
}

public void windowActivated(WindowEvent windowevent)
{
}

public void windowDeactivated(WindowEvent windowevent)
{
}

public void windowClosed(WindowEvent windowevent)
{
}


}

 /*
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ")" to complete MethodInvocation
Syntax error, insert ";" to complete Statement
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ")" to complete MethodInvocation
Syntax error, insert ";" to complete Statement
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ";" to complete Statement
Syntax error, insert ")" to complete MethodInvocation
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ")" to complete MethodInvocation
Syntax error, insert ";" to complete Statement
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ";" to complete Statement
Syntax error, insert ")" to complete MethodInvocation
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ";" to complete Statement
Syntax error, insert ")" to complete MethodInvocation
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ")" to complete MethodInvocation
Syntax error, insert ";" to complete Statement
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ";" to complete Statement
Syntax error, insert ")" to complete MethodInvocation
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ")" to complete MethodInvocation
Syntax error, insert ";" to complete Statement
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ";" to complete Statement
Syntax error, insert ")" to complete MethodInvocation
Syntax error on token ")", delete this token
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (Object)
Syntax error, insert ";" to complete Statement
Syntax error, insert ")" to complete MethodInvocation
Syntax error on token ")", delete this token

at in.ac.iitb.cfilt.hwnbrowser.WNBrowserMain.createMenuBar(WNBrowserMain.java:43)
at in.ac.iitb.cfilt.hwnbrowser.WNBrowserMain.createAndShowGUI(WNBrowserMain.java:571)
at in.ac.iitb.cfilt.hwnbrowser.WNBrowserMain.main(WNBrowserMain.java:928)*/

最佳答案

frame.addWindowListener(new  Object(type)

使用 this 而不是 new Object() 因为 addWindowListener 需要一个 WindowListener 参数,并且 this 指的是WindowListene实现的类

frame.addWindowListener(this);

  • 此外,您没有在代码中引用ActionListener actionPerformed,而您需要。甚至将 ActionListener 注册到任何组件。你没有向我们展示任何东西。

  • 此外,我完全不知道这个 class _anm1 {} 试图做什么。去掉它,按照上面指出的那样传递 this

  • 您还必须去掉方法签名中的 static,因为方法 (this) 中引用的类不是 static。如果你的类中有一堆不必要的 static 字段和 static 方法,那么你就有问题了,你面前有一个大的重构(取决于它有多糟糕).

  • difference between instance field and static field in Java 上进行 Google 搜索并阅读出现的一些结果。

  • 任何其他问题,我们将不得不查看更多代码。

关于java - 类型 AbstractButton 中的方法 addActionListener(ActionListener) 不适用于参数 (Object),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23211737/

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