Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6341517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:02:57+00:00 2026-05-24T20:02:57+00:00

I finally got this calculator application in Netbeans to compile correctly and run client-side

  • 0

I finally got this calculator application in Netbeans to compile correctly and run client-side with no errors but for some reason I cannot get it to work as an applet. I have spent a lot of time trying to figure this out and researching but to no avail. Any experts around to take a quick look and see what the problem is?

I’d really appreciate any suggestions, thanks.

package eventhandler;

import javax.swing.JApplet;

public class CalculatorApplet extends JApplet {


    @Override
    public void init() {

    }

    @SuppressWarnings("unchecked")

    private void initComponents() {

        firstText = new javax.swing.JTextField();
        secondText = new javax.swing.JTextField();
        postLabel = new javax.swing.JLabel();
        postButton = new javax.swing.JButton();
        comboBox = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        postButton.setText("Solve");
        postButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                postName(evt);
            }
        });

        comboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "+", "-", "*", "/" }));

        jButton1.setText("Clear");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearFields(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(47, 47, 47)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, secondText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, firstText)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(21, 21, 21)
                                .add(comboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(postLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(postButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 91, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jButton1)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(firstText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(secondText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(comboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(postButton)
                    .add(jButton1))
                .add(5, 5, 5)
                .add(postLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                .addContainerGap())
        );

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

    private void postName(java.awt.event.ActionEvent evt) {
        String ft = firstText.getText();
        String lt = secondText.getText(); 
        String total;
        double parse1, parse2;

        Object selectedCombo = comboBox.getSelectedItem();

        if (selectedCombo == "+") {
            parse1 = Double.parseDouble(ft);
            parse2 = Double.parseDouble(lt);
            total = String.valueOf(parse1 + parse2);
            postLabel.setText(total);

        } else if (selectedCombo == "-") {
            parse1 = Double.parseDouble(ft);
            parse2 = Double.parseDouble(lt);
            total = String.valueOf(parse1 - parse2);
            postLabel.setText(total);

        } else if (selectedCombo == "*") {
            parse1 = Double.parseDouble(ft);
            parse2 = Double.parseDouble(lt);
            total = String.valueOf(parse1 * parse2);
            postLabel.setText(total);

        } else if (selectedCombo == "/") {
            parse1 = Double.parseDouble(ft);
            parse2 = Double.parseDouble(lt);
            total = String.valueOf(parse1 / parse2);
            postLabel.setText(total);
        }

    }

    private void clearFields(java.awt.event.ActionEvent evt) {
        firstText.setText(null);
        secondText.setText(null);
    }

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

            @Override
            public void run() {
                new EventGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JComboBox comboBox;
    private javax.swing.JTextField firstText;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton postButton;
    private javax.swing.JLabel postLabel;
    private javax.swing.JTextField secondText;
    // End of variables declaration

    private void setDefaultCloseOperation(int EXIT_ON_CLOSE) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:02:58+00:00Added an answer on May 24, 2026 at 8:02 pm

    When using a applet people generally add the GUI code in the init() method. Your init() method is empty. Simple example:

    //<applet code="AppletBasic.class" width="500" height="300"></applet>
    // The above line makes it easy to test the applet from the command line by using:
    // appletviewer AppletBasic.java
    
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class AppletBasic extends JApplet
    {
        /**
         * Create the GUI. For thread safety, this method should
         * be invoked from the event-dispatching thread.
         */
        private void createGUI()
        {
            JLabel appletLabel = new JLabel( "I'm a Swing Applet" );
            appletLabel.setHorizontalAlignment( JLabel.CENTER );
            appletLabel.setFont(new Font("Serif", Font.PLAIN, 36));
            add( appletLabel );
        }
    
        public void init()
        {
            try
            {
                SwingUtilities.invokeAndWait(new Runnable()
                {
                    public void run()
                    {
                        createGUI();
                    }
                });
            }
            catch (Exception e)
            {
                System.err.println("createGUI didn't successfully complete: " + e);
            }
        }
    
        public static void main(String[] args)
        {
            JApplet applet = new AppletBasic();
            applet.init();
    
            JFrame frame = new JFrame("Applet in Frame");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add( applet );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible( true );
    
            applet.start();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've finally got this PHP email script working (didn't work on localhost…), but my
ok so i've nearly got this. But it seems there is some logic error
I finally got some understanding of how Ninject handles DI, but have faced the
I was given this code a while back. I finally got around to testing
Developing server side code i finally got my eyes X-crossed trying to write -
I read other threads like this but they didn't work for me. I got
I finally got to try .NET MVC this weekend and, as was expected, ran
I have been working on this Tab View and I finally got it working
I'm having this login system, where I've just (finally) got hash 256 added. Earlier
Finally got MGTwitterEngine stuff to compile ( by setting the Header Search Paths to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.