Basic Notepad Application

Getting error messages while trying to run a basic Notepad Application

Page 1 of 1

3 Replies - 8414 Views - Last Post: 16 December 2010 - 08:52 AM Rate Topic: -----

#1 Kochuvila  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-December 10

Basic Notepad Application

Posted 16 December 2010 - 01:08 AM

//Please find the error message I get when I try to run a basicNotepad Application



run:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
at test.note.mnuFileSaveActionPerformed(note.java:112)
at test.note.access$100(note.java:21)
at test.note$2.actionPerformed(note.java:64)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:374)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:829)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:873)
at java.awt.Component.processMouseEvent(Component.java:6175)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:5940)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4536)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4362)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
at java.awt.Container.dispatchEventImpl(Container.java:2149)
at java.awt.window.dispatchEventImpl(window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4362)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
BUILD SUCCESSFUL (total time: 33 seconds)


// Also Find the program I have tried



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * note.java
 *
 * Created on Dec 15, 2010, 3:53:07 PM
 */

package test;




/**
 *
 * @author bibinbabu
 */
public class note extends javax.swing.JFrame {



    /** Creates new form note */
    public note() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        mnuTextField = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jFile = new javax.swing.JMenu();
        mnuFileOpen = new javax.swing.JMenuItem();
        mnuFileSave = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mnuFileExit = new javax.swing.JMenuItem();
        jEdit = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Note");

        jFile.setText("File");

        mnuFileOpen.setText("Open");
        mnuFileOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuFileOpenActionPerformed(evt);
            }
        });
        jFile.add(mnuFileOpen);

        mnuFileSave.setText("Save");
        mnuFileSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuFileSaveActionPerformed(evt);
            }
        });
        jFile.add(mnuFileSave);
        jFile.add(jSeparator1);

        mnuFileExit.setText("Exit");
        mnuFileExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuFileExitActionPerformed(evt);
            }
        });
        jFile.add(mnuFileExit);

        jMenuBar1.add(jFile);

        jEdit.setText("Edit");
        jMenuBar1.add(jEdit);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mnuTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mnuTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void mnuFileExitActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        this.dispose();
    }                                           

    private void mnuFileSaveActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        public void Save()
        {
            if (canSave)
            {
                JFileChooser fileChooser = new JFileChooser();
                if (fileChooser.showSaveDialog (this)== JFileChooser.APPROVE_OPTION )
                {
                    ObjectOutputStream out;
                    try {
                        out = new ObjectOutputStream (fileChooser.getSelectedFile ());
                        out.WriteObject(this.note);
                        out.close ();

                    }
                    catch (IO Exception ex){}
                    JOptionPane.showMessageDialog(null, fileChooser.getSelectedFile(),"Message Saved",JOptionPane.INFORMATION_MESSAGE);
                }
            }canSave = false;
        }
        else
            JOptionPane.showMessageDialog(null,"Cannot save message","save error",JOptionPane.ErrorMessage);
    }                                           

    private void mnuFileOpenActionPerformed(java.awt.event.ActionEvent evt) {                                           
       
      // TODO add your handling code here:


    }                                          

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new note().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JMenu jEdit;
    private javax.swing.JMenu jFile;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuItem mnuFileExit;
    private javax.swing.JMenuItem mnuFileOpen;
    private javax.swing.JMenuItem mnuFileSave;
    private javax.swing.JTextField mnuTextField;
    // End of variables declaration

}

This post has been edited by Dogstopper: 16 December 2010 - 07:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Basic Notepad Application

#2 BigR1983  Icon User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 221
  • Joined: 12-April 10

Re: Basic Notepad Application

Posted 16 December 2010 - 05:15 AM

1) can you format your code to make is readable (place it in the code tags.
2) it has been awhile since i looked at Java, but inside
 private void mnuFileSaveActionPerformed(java.awt.event.ActionEvent evt) {
it looks like you are defining another function
public void Save()
which I believe is uncompilable code.

again I could be wrong, as I said I haven't looked at Java in awhile.

This post has been edited by BigR1983: 16 December 2010 - 05:15 AM

Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,050
  • Joined: 15-July 08

Re: Basic Notepad Application

Posted 16 December 2010 - 07:30 AM

Yep, your Save() method is inside your actionPerformed() method. You can't have methods inside of methods. It's a darned shame you are using the Netbeans GUI builder too because it locks down most of the file where you can't add anything. Don't use the GUI Builder. It is BAD practice, it is not readable to humans, and does not provide a solid framework of any kind needed to extend it.
Was This Post Helpful? 1
  • +
  • -

#4 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 497
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: Basic Notepad Application

Posted 16 December 2010 - 08:52 AM

There is also a Basic Notepad Application tutorial which you may want to check out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1