Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Cant find main class swing

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Cant find main class swing

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package swingarea;
     
    /**
     *
     * @author Logan
     */
    public class AreaCalculator extends javax.swing.JFrame {
     
        /**
         * Creates new form AreaCalculator
         */
        public AreaCalculator() {
            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() {
     
            buttonGroup1 = new javax.swing.ButtonGroup();
            dimension1Label = new javax.swing.JLabel();
            rectangleRadioButton = new javax.swing.JRadioButton();
            triangleRadioButton = new javax.swing.JRadioButton();
            dimension2Label = new javax.swing.JLabel();
            dimension1Text = new javax.swing.JTextField();
            dimension2Text = new javax.swing.JTextField();
            inchesLabel1 = new javax.swing.JLabel();
            inchesLabel2 = new javax.swing.JLabel();
            calcAreaButton = new javax.swing.JButton();
            areaLabel = new javax.swing.JLabel();
            outputLabel = new javax.swing.JLabel();
            circleRadioButton = new javax.swing.JRadioButton();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            clearMenuItem = new javax.swing.JMenu();
            exitMenuItem = new javax.swing.JMenu();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Area Calculator");
     
            dimension1Label.setText("Dimension 1:");
     
            buttonGroup1.add(rectangleRadioButton);
            rectangleRadioButton.setText("Rectangle");
     
            buttonGroup1.add(triangleRadioButton);
            triangleRadioButton.setText("Triangle");
     
            dimension2Label.setText("Dimension 2:");
     
            inchesLabel1.setText("inches");
     
            inchesLabel2.setText("inches");
     
            calcAreaButton.setText("Calculate Area");
            calcAreaButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calcAreaButtonActionPerformed(evt);
                }
            });
     
            areaLabel.setText("Area is:");
     
            buttonGroup1.add(circleRadioButton);
            circleRadioButton.setText("Circle");
     
            jMenu1.setText("File");
            jMenuBar1.add(jMenu1);
     
            clearMenuItem.setText("Clear");
            clearMenuItem.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearMenuItemActionPerformed(evt);
                }
            });
            jMenuBar1.add(clearMenuItem);
     
            exitMenuItem.setText("Exit");
            exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    exitMenuItemActionPerformed(evt);
                }
            });
            jMenuBar1.add(exitMenuItem);
     
            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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(circleRadioButton)
                                    .addComponent(dimension1Label))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(dimension1Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(inchesLabel1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(rectangleRadioButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(triangleRadioButton))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(areaLabel))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(calcAreaButton)
                                        .addComponent(outputLabel)))
                                .addGap(48, 48, 48)))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(dimension2Label)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(dimension2Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(inchesLabel2))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(circleRadioButton)
                        .addComponent(rectangleRadioButton)
                        .addComponent(triangleRadioButton))
                    .addGap(41, 41, 41)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(dimension1Label)
                        .addComponent(dimension1Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(inchesLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(dimension2Label)
                        .addComponent(dimension2Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(inchesLabel2))
                    .addGap(31, 31, 31)
                    .addComponent(calcAreaButton)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(areaLabel)
                    .addGap(20, 20, 20)
                    .addComponent(outputLabel))
            );
     
            pack();
        }// </editor-fold>
     
        private void calcAreaButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
     
        private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
     
        private void clearMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
     
        /**
         * @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(AreaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(AreaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(AreaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(AreaCalculator.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 AreaCalculator().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JLabel areaLabel;
        private javax.swing.ButtonGroup buttonGroup1;
        private javax.swing.JButton calcAreaButton;
        private javax.swing.JRadioButton circleRadioButton;
        private javax.swing.JMenu clearMenuItem;
        private javax.swing.JLabel dimension1Label;
        private javax.swing.JTextField dimension1Text;
        private javax.swing.JLabel dimension2Label;
        private javax.swing.JTextField dimension2Text;
        private javax.swing.JMenu exitMenuItem;
        private javax.swing.JLabel inchesLabel1;
        private javax.swing.JLabel inchesLabel2;
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JLabel outputLabel;
        private javax.swing.JRadioButton rectangleRadioButton;
        private javax.swing.JRadioButton triangleRadioButton;
        // End of variables declaration
    }


  2. #2
    Member suyog53's Avatar
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    37
    My Mood
    Daring
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Cant find main class swing

    What is the problem....?'
    The program runs correctly in my System...'

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Cant find main class swing

    It says cannot find main class when I try to run. This is a JFrame Swing project.

  4. #4
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Cant find main class swing

    Any help would be greatly appreciated, to sum up:
    The code is above, I have made a gui for my code but It isn't picking it up as the main. How do I set it as main? I followed a tutorial on oracle before this on swing, and it worked fine asking me to use the GUI as main, but now for whatever reason, it is not, how can i resolve this? Thanks ~ Logan Crone.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Cant find main class swing

    You have to be more explicit as to how you are running the code. Is it in a jar? Are you using the command line? Are you using an IDE? Based upon the code, I'd bet you are using an IDE with a GUI editor (which I would recommend against unless you are familiar with constructing GUI's manually).

  6. #6
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Cant find main class swing

    Assignment says you have to use Netbeans IDE.

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Cant find main class swing

    I don't use netbeans, but there must be a way to set the class which contains the application entry point (main method). The code you posted contains a main method, so I'd recommend reviewing the docs on your IDE or searching the internet for instructions on how to set the main class in Netbeans. I'll move your thread to the IDE section.

Similar Threads

  1. Execution of .jar file: Could not find main class....Error'
    By suyog53 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 14th, 2012, 02:04 PM
  2. Replies: 1
    Last Post: August 12th, 2012, 11:21 AM
  3. Replies: 2
    Last Post: March 13th, 2012, 07:45 AM
  4. newbie question: Error: Could not find or load main class Java Result: 1
    By ideaman in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 1st, 2012, 11:40 PM
  5. could not find the main class
    By Tisofa in forum Object Oriented Programming
    Replies: 1
    Last Post: September 27th, 2009, 02:58 AM