Results 1 to 2 of 2
  1. #1
    tomitzel is offline Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Question actionPerformed problem

    Hi, I'm receiveing the folowing error message:Exception in thread "main"
    java.lang.Error: Unresolved compilation problems:
    void is an invalid type for the variable actionPerformed
    Syntax error on token "(", ; expected
    Syntax error on token ")", ; expected
    The java file is this:
    Java Code:
    /**
     * 
     */
    package pachet;
    
    import java.awt.TextArea;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.*;
    
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    
    /**
     * @author Militaru Tomita
     *
     */
    public class LibrarySystem   {
    
    	Library tomex = new Library("books.txt", "members.txt");
    	public static void main(String[] args) {
    		@SuppressWarnings("unused")
    		LibrarySystem s = new LibrarySystem();
    	
    	@SuppressWarnings("deprecation")
    	
    		
    		JFrame fereastra = new JFrame("Tomex v1.0");
    		fereastra.show();
    		fereastra.setSize(500, 300);
    		JMenuBar meniu = new JMenuBar();
    		
    		JMenu menu1 = new JMenu("Carti");
    	    meniu.add(menu1);
    	    JMenuItem item1 = new JMenuItem("Adauga o carte");
    	    item1.addActionListener((ActionListener) fereastra);
    	    menu1.add(item1);
    	    JMenuItem item2 = new JMenuItem("Afiseaza toate cartile");
    	    item2.addActionListener((ActionListener) fereastra);
    	    menu1.add(item2);
    	    JMenuItem item3 = new JMenuItem("Afiseaza toate cartile disponibile");
    	    item3.addActionListener((ActionListener) fereastra);
    	    menu1.add(item3);
    	    JMenuItem item4 = new JMenuItem("Afiseaza toate cartile imprumutate");
    	    item4.addActionListener((ActionListener) fereastra);
    	    menu1.add(item4);
    	    
    	    JMenu menu2 = new JMenu("Membri");
    	    meniu.add(menu2);
    	    JMenuItem item5 = new JMenuItem("Adauga membru nou");
    	    item5.addActionListener((ActionListener) fereastra);
    	    menu2.add(item5);
    	    JMenuItem item6 = new JMenuItem("Sterge un membru");
    	    item6.addActionListener((ActionListener) fereastra);
    	    menu2.add(item6);
    	    JMenuItem item7 = new JMenuItem("Afiseaza toti membrii");
    	    item7.addActionListener((ActionListener) fereastra);
    	    menu2.add(item7);
    	    
    	    JMenu menu3 = new JMenu("Imprumuta");
    	    meniu.add(menu3);
    	    JMenuItem item8 = new JMenuItem("Imprumuta o carte");
    	    item8.addActionListener((ActionListener) fereastra);
    	    menu3.add(item8);
    	    JMenuItem item9 = new JMenuItem("Returneaza o carte");
    	    item9.addActionListener((ActionListener) fereastra);
    	    menu3.add(item9);
    	    
    	    fereastra.setJMenuBar(meniu);
    	    TextArea t = new TextArea("Hello", 5, 40);
    	    
    	    fereastra.add(t);
    	    public void [COLOR="Red"]actionPerformed[/COLOR](ActionEvent e){
    	    	
    	    }
    	}
    	
    }

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default Method definition

    Hello tomitzel

    You cannot create a new method definition inside the declaration of a method using modifiers. Also, fereastra does not implement the ActionListener interface, fereastra is only a JFrame. Try extending LibrarySystem form JFrame and let it implement ActionListener. :p
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  2. Issue with Buttons and ActionPerformed
    By Deathmonger in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 09:47 AM
  3. Help with actionPerformed Statements
    By wco5002 in forum New To Java
    Replies: 8
    Last Post: 03-26-2008, 05:02 AM
  4. Problems with jButton ActionPerformed
    By susan in forum AWT / Swing
    Replies: 3
    Last Post: 08-07-2007, 05:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •