I’m working on a Java app in NetBeans for a friend. Here is the code:
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);
}
}
}
}
I am getting an error that says:
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)
Can anyone tell me why this might be occurring? It would be greatly appreciated.
Your class
ReportGeneratorSetupneeds to be some kind of component, most likely it needs to extendJPanelorJComponent.