473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

18
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

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import javax.swing.table.*;
  4. import java.awt.event.*;
  5.  
  6. public class MainMenu extends JFrame //implements ActionListener
  7. {
  8.     private DefaultTableModel model;
  9.     private JTable table;
  10.     private JScrollPane scroll;
  11.     private JPanel panel;
  12.     private JPanel mainMenuCard;
  13.     private JLabel titleLbl;
  14.     private JButton manageCustomerBtn,manageSaleBtn,manageSaleBookBtn,makeOrderBtn,viewCartBtn,exitBtn;
  15.  
  16.  
  17.     public MainMenu()
  18.     {
  19.         super("MainMenu");
  20.         setSize(500,400);
  21.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.         createGUI();
  23.         setVisible(true);
  24.  
  25.         titleLbl=new JLabel("MAIN MENU");
  26.         manageCustomerBtn=new JButton("Manage Customer");
  27.         manageSaleBtn=new JButton("Manage Sale");
  28.         manageSaleBookBtn=new JButton("Manage Sale Book");
  29.         makeOrderBtn=new JButton("Make Order");
  30.         viewCartBtn=new JButton("View Cart");
  31.         exitBtn=new JButton("Exit");
  32.  
  33.         manageCustomerBtn.addActionListener(this);
  34.         manageSaleBtn.addActionListener(this);
  35.         manageSaleBookBtn.addActionListener(this);
  36.         makeOrderBtn.addActionListener(this);
  37.         viewCartBtn.addActionListener(this);
  38.         exitBtn.addActionListener(this);
  39.  
  40.         c.gridwidth=1;
  41.         c.gridheight=1;
  42.         c.weightx=0;
  43.         c.weighty=0;
  44.         c.fill=GridBagConstraints.HORIZONTAL;
  45.  
  46.         addComponent(titleLbl,0,0,0,0,0,0);
  47.         addComponent(manageCustomerBtn,0,1,0,0,0,0);
  48.         addComponent(manageSaleBtn,0,2,0,0,0,0);
  49.         addComponent(manageSaleBookBtn,0,3,0,0,0,0);
  50.         addComponent(makeOrderBtn,0,4,0,0,0,0);
  51.         addComponent(viewCartBtn,0,5,0,0,0,0);
  52.         addComponent(exitBtn,0,6,0,0,0,0);
  53.  
  54.     }
  55.  
  56.     public void createGUI()
  57.     {
  58.         model=new DefaultTableModel();
  59.  
  60.         int rows = 5,cols = 5;
  61.         model=new DefaultTableModel(rows,cols);
  62.  
  63.        // Object[] colNames={"Customer Id", "Customer Name","Customer Phone", "Customer Email"};
  64.        // model = new DefaultTableModel(null,colNames);
  65.  
  66.           Object[][] data={};//{1,"aaa","2015-10-08"},{2,"bbb","2015-10-08"}};
  67.           Object[] colNames={};//"john","james","joseph"};
  68.         model = new DefaultTableModel(data,colNames)
  69.         {
  70.             public boolean isCellEditable(int row,int col)
  71.             {
  72.                 return false;
  73.             }
  74.         };
  75.  
  76.         table=new JTable(model)
  77.         {
  78.             boolean[] cellEditables={false,true,true};
  79.             public boolean isCellEditable(int row,int col)
  80.             {
  81.                 return cellEditables[col];
  82.             }            
  83.         };
  84.  
  85.         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  86.  
  87.         scroll=new JScrollPane(table);
  88.         scroll.setPreferredSize(new Dimension(350,250));
  89.         panel=new JPanel();
  90.         panel.add(scroll);
  91.         add(panel);
  92.     }
  93.  
  94.     public static void main(String[] args)
  95.     {
  96.         new MainMenu();
  97.     }
  98. }
  99.  
  100.  
a pic of the problem is attached.
Thanks in advance.
Attached Images
File Type: jpg ActionListener.jpg (43.4 KB, 453 views)
Oct 21 '15 #1
3 5572
chaarmann
785 Expert 512MB
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.
Expand|Select|Wrap|Line Numbers
  1. public class MainMenu extends JFrame implements ActionListener
Oct 21 '15 #2
babs115
18
sorry, please how I use auto-complete to create the missing method? This is new to me. Thanks in advance.
Oct 22 '15 #3
chaarmann
785 Expert 512MB
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.
Oct 23 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: linux newbie | last post by:
is there any java expert could tell me what the problem below and explain the code to me, your explanation is greatly appreciated :) static Class class$java$awt$event$ActionListener; ...
2
by: Dennis Schulz | last post by:
Hi all, the following programm is supposed to check for login and password with inbuilt linux functions. in line 57 and 64 there are erorrs: incompatible types in asignment. whats wrong with...
3
by: Randy Fraser | last post by:
What is the proper way of declaring an override on a button click event for a base form. I am getting " Cannot bind an event handler to the 'Click' event because it is read only." listed in the...
16
by: v4vijayakumar | last post by:
Whats wrong with the code in line no. 7?! #cat test3.c #include <stdio.h> int main(int argc, char *argv) { int ia1 = {0, 1, 2}; int ia2; ia2 = ia1;
8
by: fei.liu | last post by:
I have the following source code. It seems wierd to me why gca's value cannot be reassigned. It's afterall a pointer and has a pointer value. I am aware that the standard says it's not allowed. But...
1
by: hgoren | last post by:
hi everyone, I am having a trouble in my code. It gives the following error: Incompatible types in assignment of 'int*' to int Here is my code: #include<stdio.h> #include<stdlib.h>...
4
by: pandaemonium | last post by:
I have two quick problems with the code I am writing: First, I define a struct of char arrays (strings) and then try accessing the same. I get an "incompatible types in assignment" error: struct...
2
by: kardon33 | last post by:
I am getting a "error: incompatible types in assignment" error and cant figure out why? I am trying to set lastRow to row at the end of the code snippet. int row; int lastRow; size_t...
1
by: Jatinmalhotra | last post by:
import java.io.*; class CAcc { String name=new String; long accno; char type; double Bal; CAcc(String Name,long Accno,char Type,double bal) {
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.