Results 1 to 5 of 5
  1. #1
    Zeezj's Avatar
    Zeezj is offline Member
    Join Date
    Mar 2011
    Location
    Cambridge, MA
    Posts
    11
    Rep Power
    0

    Exclamation Swing application getting odd errors

    hello, im trying to code a simple application that factors a number, and i already have that part of the code, but i've been trying to build a gui for it. i was using a tutorial on oracle.com and it was very helpful, but i'm getting a weird error.

    here's the error:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
    	at factor.FactorerGUI.factorButtonActionPerformed(FactorerGUI.java:110)
    	at factor.FactorerGUI.access$000(FactorerGUI.java:17)
    	at factor.FactorerGUI$1.actionPerformed(FactorerGUI.java:50)
    	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.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
    	at java.awt.Component.processMouseEvent(Component.java:6203)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    	at java.awt.Component.processEvent(Component.java:5968)
    	at java.awt.Container.processEvent(Container.java:2105)
    	at java.awt.Component.dispatchEventImpl(Component.java:4564)
    	at java.awt.Container.dispatchEventImpl(Container.java:2163)
    	at java.awt.Component.dispatchEvent(Component.java:4390)
    	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:4390)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:649)
    	at java.awt.EventQueue.access$000(EventQueue.java:96)
    	at java.awt.EventQueue$1.run(EventQueue.java:608)
    	at java.awt.EventQueue$1.run(EventQueue.java:606)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
    	at java.awt.EventQueue$2.run(EventQueue.java:622)
    	at java.awt.EventQueue$2.run(EventQueue.java:620)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:619)
    	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)
    and here's the code(the error is something about where it says "public static void main(String args[])":
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * FactorerGUI.java
     *
     * Created on Sep 14, 2011, 10:56:44 AM
     */
    package factor;
    
    /**
     *
     * @author xindi_guy_vi
     */
    public class FactorerGUI extends javax.swing.JFrame {
    
        /** Creates new form FactorerGUI */
        public FactorerGUI() {
            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() {
    
            factorerTitle = new javax.swing.JLabel();
            numberToFactorLabel = new javax.swing.JLabel();
            factoredNumberField = new javax.swing.JTextField();
            factorButton = new javax.swing.JButton();
            factorList = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Factorer");
    
            factorerTitle.setFont(new java.awt.Font("Embossing Tape 1 BRK", 0, 15)); // NOI18N
            factorerTitle.setText("     THE AMAZING NUMBER FACTORER");
    
            numberToFactorLabel.setText("number to factor:");
    
            factorButton.setText("Factor!");
            factorButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    factorButtonActionPerformed(evt);
                }
            });
    
            factorList.setBackground(new java.awt.Color(255, 255, 255));
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(factorerTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(33, 33, 33)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(factorButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(factorList, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(numberToFactorLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(factoredNumberField, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)))))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(factorerTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(factoredNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(numberToFactorLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(factorList, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                        .addComponent(factorButton, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>
    
        private void factorButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            double i = (Double.parseDouble(factoredNumberField.getText()));
            double a;
            int b;
            for (b=1;b<=i;b++) {
                a = i%b;
                if (a==0) {
                    factorList.setText(b + "");
                }
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(FactorerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(FactorerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(FactorerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(FactorerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new FactorerGUI().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JButton factorButton;
        private javax.swing.JLabel factorList;
        private javax.swing.JTextField factoredNumberField;
        private javax.swing.JLabel factorerTitle;
        private javax.swing.JLabel numberToFactorLabel;
        // End of variables declaration
    }
    from the desk of August Underhill-Proulx, CEO of Awesomecorp ltd.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Swing application getting odd errors

    You ignored a compiler error; fix that first before you try to run your (invalid) class file.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Zeezj's Avatar
    Zeezj is offline Member
    Join Date
    Mar 2011
    Location
    Cambridge, MA
    Posts
    11
    Rep Power
    0

    Default Re: Swing application getting odd errors

    You ignored a compiler error; fix that first before you try to run your (invalid) class file.

    kind regards,

    Jos
    im kind of a java noob, what does that mean?
    from the desk of August Underhill-Proulx, CEO of Awesomecorp ltd.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Swing application getting odd errors

    Quote Originally Posted by Zeezj View Post
    im kind of a java noob, what does that mean?
    Read what the Exception has to say:

    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - illegal start of expressio
    There is something wrong in your code and your compiler tried to tell you exactly where but you ignored it and tried to run the (invalid) compiled code. Recompile and see what the compiler has to say about it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Swing application getting odd errors

    Count your opening { and closing } braces around the line mentioned in the compiler error.

    db

Similar Threads

  1. Existing swing application
    By macason in forum AWT / Swing
    Replies: 3
    Last Post: 11-30-2009, 10:51 PM
  2. Better Swing Application Framework
    By etf in forum Java Software
    Replies: 1
    Last Post: 09-07-2009, 02:25 PM
  3. designing application in swing
    By programmer_007 in forum AWT / Swing
    Replies: 12
    Last Post: 09-03-2009, 07:50 PM
  4. deployment of swing application
    By makpandian in forum AWT / Swing
    Replies: 1
    Last Post: 12-26-2008, 04:08 PM
  5. Swing Application Framework
    By jurka in forum AWT / Swing
    Replies: 0
    Last Post: 10-09-2008, 06:01 PM

Tags for this Thread

Posting Permissions

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