Results 1 to 3 of 3

Thread: Parsing Error

  1. #1
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    79
    Rep Power
    0

    Default Parsing Error

    Hi,

    I have just carried out a task based on some Java code from a book. But when I try to build my code, I get an error message 'reached end of file while parsing' and it points me to the last line of my code. My code is below, could someone tell me what is wrong please?

    Java Code:
    import java.awt.EventQueue;
    import java.awt.event.*;
    import javax.swing.*;
    
    /**
    *@version 1.23 2009-08-31
    *@author Menre (work lifted from a book)
    */
    
    public class MenuTest
    
       {
    
       public static void main(String args [])
         {
    
         EventQueue.invokeLater(new Runnable()
            {
              public void run()
               {
                MenuFrame frame = new MenuFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
                  }
                 });
             }
    
       /**A frame with a sample menu bar.
           */
       class MenuFrame extends JFrame
        {
         public MenuFrame()
          {
            setTitle("MenuTest");
            setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    
            JMenu fileMenu = new JMenu("File");
            fileMenu.add(new TestAction("New"));
    
         // demonstrates accelerators
    
          JMenuItem openItem = fileMenu.add(new TestAction("Open"));
          openItem.setAccelerator(keyStroke.getkeyStroke("ctrl O"));
    
          fileMenu.addSeparator();
      
          saveAction = new TestAction("Save");
          JMenuItem saveItem = fileMenu.add(saveAction);
          saveItem.setAccelerator(keyStroke.getKeyStroke("ctrl S"));
    
          saveAsAction = new TestAction("Save As");
          fileMenu.add(SaveAsAction);
          fileMenu.addSeparator();
    
          fileMenu.add(new Abstraction("Exit")
             {
              public void actionPerformed(ActionEvent event)
               {
                  System.exit(0);
                }
              });
    
         // demonstrate check box and radio button menus
           
            readonlyItem = new JCheckBoxMenuItem("Read-only");
            readonlyItem.addActionListener(new ActionListener()
                 {
                  public void actionPerformed(ActionEvent event)
                     {
                       boolean saveOK = !readonlyItem.isSelected();
                       saveAction.setEnabled(saveOk);
                       saveAsAction.setEnabled(saveOk);
                     }
                   });
    
              ButtonGroup group = new ButtonGroup();
    
            JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert");
            insertItem.setSelected(true);
            JRadioButtonMenuItem overtypeItem = new JRadioButtonMenu("Overtype");
             
            Action cutAction = new TestAction("Cut");
            cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif"));
            Action copyAction = new TestAction("Copy");
            copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif"));
            Action pasteAction = new TestAction("Paste");
            pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif"));
    
          JMenu editMenu = new JMenu("Edit");
          editMenu.add(cutAction);
    
         editmenu.add(copyAction);
         editMenu.add(pasteAction);
    
        //demonstrate nested menus
    
       JMenu optionMenu = new JMenu("Options");
    
       optionMenu.add(readonlyItem);
       optionMenu.addSeparator();
       optionMenu.add(insertItem);
       optionMenu.add(overtypeItem);
    
       editMenu.addSeparator();
       editMenu.add(optionMenu);
    
      //demonstrate mnemonics
    
       JMenu helpMenu = new JMenu("Help");
       helpMenu.setMnemonic('H');
    
       JMenuItem indexItem = new JMenuItem("Index");
       indexItem.setMnemonic('I');
       helpMenu.add(indexItem);
    
      // you can also add the mnemonic key to an action
    
        Action aboutAction = new TestAction("About");
        aboutAction.putValue(Action.MNEMONIC_KEY, new Integer('A'));
        helpMenu.add(aboutAction);
    
      // add all top-level menus to menu bar
    
        JMenuBar = new JMenubar();
        setJMenuBar(menuBar);
    
       menuBar.add(fileMenu);
       menuBar.add(editMenu);
       menuBar.add(helpMenu);
    
     // demonstrate pop-ups
    
        popup = new JPopupMenu();
        popup.add(cutAction);
        popup.add(copyAction);
        popup.add(pasteAction);
    
        JPanel panel = new JPanel();
        panel.setComponentPopupMenu(popup);
        add.(panel);
    
       // the folowing line is a workaround for bug 4966109
            panel.addMouseListener(new MouseAdapter()
             {
             });
           }
    
           public static final int DEFAULT_WIDTH = 300;
           public static final int DEFAULT_HEIGHT = 200;
    
           private Action saveAction;
           private Action saveAsAction;
           private JCheckBoxMenuItem readonlyItem;
           private JPopupMenu popup;
      }
    
      /**
        * A sample action that prints the action name to System.out
         **/
       
           class TestAction extends AbstractAction
             {
               public TestAction(string name)
                {
                  super(name);
                }
                 public void actionPerformed(ActionEvent event)
                  {
                      System.out.println(getValue(Action.NAME) + " selected.");
             }
           }
    Thanks in advance,
    Menre

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    There are a number of typos in this code. I would go through it again and fix them.
    My Hobby Project: LegacyClone

  3. #3
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    79
    Rep Power
    0

    Thumbs up

    Hi,

    Thank you for your suggestion. I have checked it again and there were actually many typos. I have corrected them and the programme is now working fine.

    Menre

Similar Threads

  1. Parsing XML
    By virvalid in forum Advanced Java
    Replies: 3
    Last Post: 08-10-2009, 01:40 PM
  2. Parsing
    By Matt Sakko in forum New To Java
    Replies: 14
    Last Post: 03-21-2009, 05:49 PM
  3. Xml Parsing
    By Nomad in forum XML
    Replies: 12
    Last Post: 02-22-2009, 12:19 PM
  4. Error while parsing html page in java on linux
    By rdhaware in forum Advanced Java
    Replies: 1
    Last Post: 02-20-2009, 03:20 AM
  5. xml parsing help
    By tankhardrive in forum XML
    Replies: 2
    Last Post: 02-12-2009, 12:45 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
  •