簡體   English   中英

沒有為add()找到合適的方法

[英]no suitable method found for add( )

我正在為朋友在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)

誰能告訴我為什么會發生這種情況? 這將不勝感激。

您的類ReportGeneratorSetup需要是某種組件,很可能需要擴展JPanelJComponent

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM