我正在为一个朋友在 NetBeans 中开发一个 Java 应用程序。这是代码:
public class ReportGenerator extends JFrame implements ActionListener {
//GUI components
private JMenuBar menuBar;
private JMenu fileMenu;
private JMenuItem newItem;
private JMenuItem openItem;
private JMenuItem exitItem;
private ReportGeneratorSetup setup;
private ReportGeneratorProgram application;
public ReportGenerator()
{
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
exitItem = new JMenuItem("Exit");
fileMenu.add(exitItem);
exitItem.addActionListener(this);
menuBar.add(fileMenu);
this.setJMenuBar(menuBar);
this.setSize(1000,1200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
setup = new ReportGeneratorSetup(this);
application = new ReportGeneratorProgram(this,setup);
//this.add(setup);
this.validate();
}
public static void main(String[] args) {
ReportGenerator rg = new ReportGenerator();
}
public void switchToPanel(String panel)
{
this.getContentPane().removeAll();
if(panel.equals("Eval"))
{
application.setupComponents();
this.getContentPane().add(application);
}
else if(panel.equals("Setup"))
{
this.getContentPane().add(setup);
}
this.invalidate();
this.validate();
}
@Override
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() instanceof JMenuItem)
{
JMenuItem item = (JMenuItem)arg0.getSource();
if(item.getText().equals("Exit"))
{
dispose();
System.exit(0);
}
}
}
}
我收到一条错误消息:
no suitable method found for add(reportgenerator.ReportGeneratorSetup)
method java.awt.Container.add(java.awt.Component,java.lang.Object,int) is not applicable
(actual and formal argument lists differ in length)
method java.awt.Container.add(java.awt.Component,java.lang.Object) is not applicable
(actual and formal argument lists differ in length)
method java.awt.Container.add(java.awt.Component,int) is not applicable
(actual and formal argument lists differ in length)
method java.awt.Container.add(java.lang.String,java.awt.Component) is not applicable
(actual and formal argument lists differ in length)
method java.awt.Container.add(java.awt.Component) is not applicable
(actual argument reportgenerator.ReportGeneratorSetup cannot be converted to java.awt.Component by method invocation conversion)
method java.awt.Component.add(java.awt.PopupMenu) is not applicable
(actual argument reportgenerator.ReportGeneratorSetup cannot be converted to java.awt.PopupMenu by method invocation conversion)
谁能告诉我为什么会发生这种情况?这将不胜感激。