Results 1 to 3 of 3
  1. #1
    barney is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Error: <identifier> expected

    Hi, I am attempting to write a java swing application, the source code follows:

    Java Code:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.swing.*;
    
    //A generic window Listener
    class GenericWindowListener extends WindowAdapter {
    
    	public void windowClosing(WindowEvent event){
    	
    		System.exit(0);
    		
    	}//end windowClosing
    	
    }//end GenericWindowListener
    
    //The class containing my main frame
    class MainFrame extends JFrame {
    
    	public MainFrame(){
    	
    		super("Dictionary");
    		
    		setSize(500,500);
    	
    	}//end mainFrame
    	
    }//end MainFraim
    
    //main class
    public class Java_graphic_version {
    
    	MainFrame app=new MainFrame();
    	
    	app.addWindowListener(new GenericWindowListener());
    	
    	app.show();
    
    }//end Java_graphic_version
    Only the classes currently being instantiated are shown.

    For some reason, my IDE shows up two errors. One at the line stating
    Java Code:
    app.addWindowListener(new GenericWindowListener());
    the other at the line stating
    Java Code:
    app.show();
    the error for both lines is the same:
    Java Code:
    <identifier> expected
    The only thing I could possible see that is screwing up is the lack of any JPanel, or any content at all, being placed in the frame, but I don't understand why that should matter.
    Thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    public class Java_graphic_version {
        public static void main(String[] args) {
            MainFrame app=new MainFrame();
            app.addWindowListener(new GenericWindowListener());
            // The show method is deprecated - see api.
    //        app.show();
            app.setVisible(true);
        }
    }//end Java_graphic_version

  3. #3
    nitinborge5 is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    hi hardwired

    do one thing put your all code in main method from Java_graphic_version

    then it will work and there is one more mistake did by u is

    import javax

    and not java for swing ok,





    Java Code:
    public class Java_graphic_version {
    
    	public static void main(String []args)
    	{
    	MainFrame app=new MainFrame();
    	
    	app.addWindowListener(new GenericWindowListener());
    	
    	app.show();
    	}
    
    }//end Java_graphic_version

Similar Threads

  1. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 05:49 PM
  2. Error: ')' expected
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:32 AM
  3. Error: '{' expected
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-26-2007, 09:34 AM
  4. My error is: ')' expected
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 04:49 PM
  5. MSG ERROR: : expected
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 02:21 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
  •