incompatible types: MainMenu cannot be converted to java.awt.event.ActionListener

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babs115
    New Member
    • Jun 2015
    • 18

    incompatible types: MainMenu cannot be converted to java.awt.event.ActionListener

    Can someone please help? Why am I getting this error massage from code[incompatible types: MainMenu cannot be converted to java.awt.event. ActionListener]

    Here is the CODE

    Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    
    public class MainMenu extends JFrame //implements ActionListener
    {
        private DefaultTableModel model;
        private JTable table;
        private JScrollPane scroll;
        private JPanel panel;
        private JPanel mainMenuCard;
        private JLabel titleLbl;
        private JButton manageCustomerBtn,manageSaleBtn,manageSaleBookBtn,makeOrderBtn,viewCartBtn,exitBtn;
    
        
        public MainMenu()
        {
            super("MainMenu");
            setSize(500,400);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            createGUI();
            setVisible(true);
            
            titleLbl=new JLabel("MAIN MENU");
            manageCustomerBtn=new JButton("Manage Customer");
            manageSaleBtn=new JButton("Manage Sale");
            manageSaleBookBtn=new JButton("Manage Sale Book");
            makeOrderBtn=new JButton("Make Order");
            viewCartBtn=new JButton("View Cart");
            exitBtn=new JButton("Exit");
            
            manageCustomerBtn.addActionListener(this);
            manageSaleBtn.addActionListener(this);
            manageSaleBookBtn.addActionListener(this);
            makeOrderBtn.addActionListener(this);
            viewCartBtn.addActionListener(this);
            exitBtn.addActionListener(this);
            
            c.gridwidth=1;
            c.gridheight=1;
            c.weightx=0;
            c.weighty=0;
            c.fill=GridBagConstraints.HORIZONTAL;
            
            addComponent(titleLbl,0,0,0,0,0,0);
            addComponent(manageCustomerBtn,0,1,0,0,0,0);
            addComponent(manageSaleBtn,0,2,0,0,0,0);
            addComponent(manageSaleBookBtn,0,3,0,0,0,0);
            addComponent(makeOrderBtn,0,4,0,0,0,0);
            addComponent(viewCartBtn,0,5,0,0,0,0);
            addComponent(exitBtn,0,6,0,0,0,0);
            
        }
        
        public void createGUI()
        {
            model=new DefaultTableModel();
            
            int rows = 5,cols = 5;
            model=new DefaultTableModel(rows,cols);
            
           // Object[] colNames={"Customer Id", "Customer Name","Customer Phone", "Customer Email"};
           // model = new DefaultTableModel(null,colNames);
            
              Object[][] data={};//{1,"aaa","2015-10-08"},{2,"bbb","2015-10-08"}};
              Object[] colNames={};//"john","james","joseph"};
            model = new DefaultTableModel(data,colNames)
            {
                public boolean isCellEditable(int row,int col)
                {
                    return false;
                }
            };
            
            table=new JTable(model)
            {
                boolean[] cellEditables={false,true,true};
                public boolean isCellEditable(int row,int col)
                {
                    return cellEditables[col];
                }            
            };
            
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            
            scroll=new JScrollPane(table);
            scroll.setPreferredSize(new Dimension(350,250));
            panel=new JPanel();
            panel.add(scroll);
            add(panel);
        }
        
        public static void main(String[] args)
        {
            new MainMenu();
        }
    }
    a pic of the problem is attached.
    Thanks in advance.
    Attached Files
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Your main menu must implement an interface (and its methods), else it cannot be used as an action listener.

    Just remove your comments in line 6 (see below) and use auto-complete to create the missing methods.
    Code:
    public class MainMenu extends JFrame implements ActionListener

    Comment

    • babs115
      New Member
      • Jun 2015
      • 18

      #3
      sorry, please how I use auto-complete to create the missing method? This is new to me. Thanks in advance.

      Comment

      • chaarmann
        Recognized Expert Contributor
        • Nov 2007
        • 785

        #4
        In Eclipse, the word "MainMenu" would be underlined. You just right-click (not left-click) on it and an option pops up with "create missing methods". Then you can find the new methods at the end of your program.

        Comment

        Working...