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 9288271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:52:33+00:00 2026-06-18T19:52:33+00:00

I am currently creating a Calculator project in java and right now I am

  • 0

I am currently creating a Calculator project in java and right now I am only making the design or the GUI for it. This is my code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

    public class Calculator extends JFrame {

          JButton jcomp1;
             JButton jcomp2;
          JButton jcomp3;
            JTextField jcomp4;
            JTextField jcomp5;
            JRadioButton rb1;
            JRadioButton jcomp7;
            JRadioButton jcomp8;
            JRadioButton jcomp9;
            JRadioButton jcomp10;
            JRadioButton jcomp11;
            JLabel jcomp12;
            JLabel jcomp13;
            JButton jcomp14;
            JButton jcomp15;
            JButton jcomp16;
            JButton jcomp17;
            JButton jcomp18;
            JButton jcomp19;
            JButton jcomp20;
            JButton jcomp21;
            JButton jcomp22;
            JButton jcomp23;
            JButton jcomp24;
            JButton jcomp25;
            JButton jcomp26;
            JButton jcomp27;
            JButton jcomp28;
            JButton jcomp29;
            JButton jcomp30;
            JButton jcomp31;
            JButton jcomp32;
            JButton jcomp33;
            JButton jcomp34;
            JButton jcomp35;

            public Calculator() {

                jcomp1 = new JButton ("A");
                jcomp2 = new JButton ("CE");
                jcomp3 = new JButton ("C");
                jcomp4 = new JTextField (5);
                jcomp5 = new JTextField (5);
                rb1 = new JRadioButton ("Hex");
                jcomp7 = new JRadioButton ("Dec");
                jcomp8 = new JRadioButton ("Oct");
                jcomp9 = new JRadioButton ("Bin");
                jcomp10 = new JRadioButton ("On");
                jcomp11 = new JRadioButton ("Off");
                jcomp12 = new JLabel ("Palindrome");
                jcomp13 = new JLabel ("Test");
                jcomp14 = new JButton ("?");
                jcomp15 = new JButton ("B");
                jcomp16 = new JButton ("C");
                jcomp17 = new JButton ("D");
                jcomp18 = new JButton ("E");
                jcomp19 = new JButton ("F");
                jcomp20 = new JButton ("7");
                jcomp21 = new JButton ("4");
                jcomp22 = new JButton ("1");
                jcomp23 = new JButton ("0");
                jcomp24 = new JButton ("8");
                jcomp25 = new JButton ("5");
                jcomp26 = new JButton ("2");
                jcomp27 = new JButton (".");
                jcomp28 = new JButton ("3");
                jcomp29 = new JButton ("6");
                jcomp30 = new JButton ("9");
                jcomp31 = new JButton ("+");
                jcomp32 = new JButton ("-");
                jcomp33 = new JButton ("/");
                jcomp34 = new JButton ("*");
                jcomp35 = new JButton ("=");

                setPreferredSize (new Dimension (363, 312));
                setLayout (null);

                add (jcomp1);
                add (jcomp2);
                add (jcomp3);
                add (jcomp4);
                add (jcomp5);
                add (rb1);
                add (jcomp7);
                add (jcomp8);
                add (jcomp9);
                add (jcomp10);
                add (jcomp11);
                add (jcomp12);
                add (jcomp13);
                add (jcomp14);
                add (jcomp15);
                add (jcomp16);
                add (jcomp17);
                add (jcomp18);
                add (jcomp19);
                add (jcomp20);
                add (jcomp21);
                add (jcomp22);
                add (jcomp23);
                add (jcomp24);
                add (jcomp25);
                add (jcomp26);
                add (jcomp27);
                add (jcomp28);
                add (jcomp29);
                add (jcomp30);
                add (jcomp31);
                add (jcomp32);
                add (jcomp33);
                add (jcomp34);
                add (jcomp35);

                jcomp1.setBounds (90, 100, 50, 30);
                jcomp2.setBounds (145, 100, 50, 30);
                jcomp3.setBounds (200, 100, 50, 30);
                jcomp4.setBounds (0, 0, 365, 40);
                jcomp5.setBounds (0, 45, 365, 40);
                rb1.setBounds (0, 100, 50, 25);
                jcomp7.setBounds (0, 120, 70, 25);
                jcomp8.setBounds (0, 145, 70, 25);
                jcomp9.setBounds (0, 170, 60, 25);
                jcomp10.setBounds (0, 245, 65, 25);
                jcomp11.setBounds (0, 270, 65, 25);
                jcomp12.setBounds (5, 205, 75, 25);
                jcomp13.setBounds (20, 220, 45, 25);
                jcomp14.setBounds (255, 100, 105, 30);
                jcomp15.setBounds (90, 135, 50, 30);
                jcomp16.setBounds (90, 170, 50, 30);
                jcomp17.setBounds (90, 205, 50, 30);
                jcomp18.setBounds (90, 240, 50, 30);
                jcomp19.setBounds (90, 275, 50, 30);
                jcomp20.setBounds (145, 135, 50, 30);
                jcomp21.setBounds (145, 170, 50, 30);
                jcomp22.setBounds (145, 205, 50, 30);
                jcomp23.setBounds (145, 240, 105, 30);
                jcomp24.setBounds (200, 135, 50, 30);
                jcomp25.setBounds (200, 170, 50, 30);
                jcomp26.setBounds (200, 205, 50, 30);
                jcomp27.setBounds (255, 240, 50, 30);
                jcomp28.setBounds (255, 205, 50, 30);
                jcomp29.setBounds (255, 170, 50, 30);
                jcomp30.setBounds (255, 135, 50, 30);
                jcomp31.setBounds (310, 135, 50, 30);
                jcomp32.setBounds (310, 170, 50, 30);
                jcomp33.setBounds (310, 205, 50, 30);
                jcomp34.setBounds (310, 240, 50, 30);
                jcomp35.setBounds (145, 275, 215, 30);

            }

            public static void main (String[] args) {
                Calculator calc = new Calculator();
                calc.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
                calc.getContentPane().add (new Calculator());
                calc.pack();
                calc.setVisible (true);
            }


    }

I am using eclipse to make this layout but I’m afraid I keep getting the error:

 Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
        at java.awt.Container.checkNotAWindow(Container.java:429)
        at java.awt.Container.addImpl(Container.java:1037)
        at java.awt.Container.add(Container.java:363)
        at Calculator.main(Calculator.java:162)

Can you point out what did I do wrong? I tried making a design in GuiGenie but also I still get this error.

  • 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-06-18T19:52:35+00:00Added an answer on June 18, 2026 at 7:52 pm

    The problem:

    calc.getContentPane().add (new Calculator());
    

    All of your buttons, text fields, etc., should be added to a JPanel, and the JPanel should be added to the content pane of the JFrame.

    To do this:

    • create a JPanel in the constructor of your Calculator.
    • add all your JComponents to the JPanel.
    • in the Calculator constructor, add this code: this.getContentPane().add(jPanel);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a poker system and I am currently streamlining my hand calculator.
I am currently creating an application for compiling multiple java projects in one go
I'm currently creating a neighbourhood graph by doing roughly this: for every voxel look
I'm relatively new to bash programming and i am currently creating a simple calculator.
Firstly, this may sound very trivial, but currently I am creating a function getQuadrant(degree)
im currently creating a graph for an app, using coreplot and have a problem
I'm currently creating a payment SDK for android, as such I want to send
I'm currently creating an iPhone app (Xcode 4.3.1, IOS 5) that could use Bluetooth
I'm currently creating a iOS 5 iPad app where there will be heavy network
I'm currently creating a form validation script based on the jQuery validator plugin .

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.