I follows this. javax.swing.event.MenuListener - Menu Listener Interface
And i keep getting this error. Note, i have not added it to the menu objects.
Sorry for the long code guys!
package interfacepkg; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; /** * * @author Josh Kruger */ public class Main extends JFrame implements MenuListener{ JTextField ClientName = new JTextField(20); JTextField DOB = new JTextField(9); JButton ok = new JButton("Ok"); JButton Can = new JButton("Cancel"); //-------------------------------------------------------------- JMenuBar Tools = new JMenuBar(); JMenu AddClients = new JMenu("Add Clients"); JMenuItem addone = new JMenuItem("Add a Client"); JMenu EditClients = new JMenu("Edit Clients"); JMenuItem PickCurrent = new JMenuItem("Choose Client"); JMenuItem EditHim = new JMenuItem("Edit Choosen Client"); JMenuItem RemoveC = new JMenuItem("Remove a Client"); JMenu Fresh = new JMenu("Advanced"); JMenuItem reset = new JMenuItem("Reset Data"); JMenuItem restart = new JMenuItem("Re-Build Pages"); //----------------------------------------------------------------- public void Window1() { setTitle("Test Interface"); setSize(400,150); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); AddClients.add(addone); EditClients.add(PickCurrent); EditClients.add(EditHim); EditClients.addSeparator(); EditClients.add(RemoveC); Fresh.add(reset); Fresh.addSeparator(); Fresh.add(restart); Tools.add(AddClients); Tools.add(EditClients); Tools.add(Fresh); setJMenuBar(Tools); GridLayout gridall = new GridLayout(3,3,5,8); JPanel pane = new JPanel(); pane.setLayout(gridall); JLabel Name = new JLabel("Name: "); JLabel Date = new JLabel("Date of Birth"); pane.add(Name); pane.add(ClientName); pane.add(Date); pane.add(DOB); pane.add(ok); pane.add(Can); add(pane); setVisible(true); } public void menuSelected(MenuEvent e) { JMenu myMenu = (JMenu) e.getSource(); System.out.println("Menu Selected: "+myMenu.getText()); } public void actionPeformed(ActionEvent evt) { Object source = evt.getSource(); if(source == addone) { setTitle("addone worked"); } repaint(); } public static void main(String[] args) { Main Start = new Main(); Start.Window1(); // TODO code application logic here } }
This is the error i get... (In the book java6 in 21 days, his examples, as well as the link implement fine)
java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Uncompilable source code -[B] interfacepkg.Main is not abstract and does not override abstract method menuCanceled(javax.swing.event.MenuEvent) in javax.swing.event.MenuListener[/B] at interfacepkg.Main.<clinit>(Main.java:18) Could not find the main class: interfacepkg.Main. Program will exit. Exception in thread "main" Java Result: 1
Thanks guys!!!