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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:16:20+00:00 2026-05-26T09:16:20+00:00

hi there i am trying to make a calculator with coding sizes,layouts etc. by

  • 0

hi there i am trying to make a calculator with coding sizes,layouts etc. by myself (trying to not use NetBeans and it is not a homework). but i am facing with a problem about empty spaces. i have a TextArea and Buttons but as you can see below i cant handle this space problem. here is my code,

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextArea;

public class calculator extends JFrame {

    public calculator(){

        initComponents();

    }

    private void initComponents(){

        JPanel panelScreen = new JPanel(new GridLayout(0,1));

        JTextArea screen = new JTextArea();
        panelScreen.add(screen);

        JFrame frame = new JFrame("CALCULATOR");
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

        JPanel panelButtons = new JPanel(new GridLayout(3,3));

        JButton oneButton = new JButton("1");
        panelButtons.add(oneButton);

        JButton twoButton = new JButton("2");
        panelButtons.add(twoButton);

        JButton threeButton = new JButton("3");
        panelButtons.add(threeButton);

        JButton fourButton = new JButton("4");
        panelButtons.add(fourButton);

        JButton fiveButton = new JButton("5");
        panelButtons.add(fiveButton);

        JButton sixButton = new JButton("6");
        panelButtons.add(sixButton);

        JButton sevenButton = new JButton("7");
        panelButtons.add(sevenButton);

        JButton eightButton = new JButton("8");
        panelButtons.add(eightButton);

        JButton nineButton = new JButton("9");
        panelButtons.add(nineButton);

        frame.getContentPane().add(panelScreen, BorderLayout.NORTH);
        //frame.getContentPane().add(new JSeparator(), BorderLayout.CENTER);
        frame.getContentPane().add(panelButtons, BorderLayout.SOUTH);
        frame.setBounds(50, 50, 500, 500);
        frame.setResizable(false);
        //frame.pack();
        frame.setVisible(true);


    }


    public static void main(String[] args) {

        new calculator();

    }

}

and this the picture of programme;

enter image description here

i appreciate if you can help me. anyway thanks 🙂

  • 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-26T09:16:20+00:00Added an answer on May 26, 2026 at 9:16 am

    Calculator GUI

    import java.awt.*;
    
    import javax.swing.*;
    import javax.swing.border.EmptyBorder;
    
    // no need to extend frame!
    //public class Calculator extends JFrame {
    public class Calculator {
    
        public Calculator(){    
            initComponents();    
        }
    
        private void initComponents(){
            // I find it easier to create a panel and SET it as the content pane
            JPanel gui = new JPanel(new BorderLayout(5,5));
            // add some padding to the main GUI
            gui.setBorder(new EmptyBorder(4,4,4,4));
    
            // not needed if only a single compoinent is to be added!
            //JPanel panelScreen = new JPanel(new GridLayout(0,1));
    
            // add some constraints to make the output field bigger.
            // if it is intended to be single line, a JTextField should be used.
            JTextArea screen = new JTextArea(2,25);
            gui.add(screen, BorderLayout.NORTH);
            //panelScreen.add(screen);
    
            JFrame frame = new JFrame("CALCULATOR");
            frame.setContentPane(gui);
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            // add padding around the buttons
            JPanel panelButtons = new JPanel(new GridLayout(3,3,4,4));
    
            JButton oneButton = new JButton("1");
            panelButtons.add(oneButton);
    
            JButton twoButton = new JButton("2");
            panelButtons.add(twoButton);
    
            JButton threeButton = new JButton("3");
            panelButtons.add(threeButton);
    
            JButton fourButton = new JButton("4");
            panelButtons.add(fourButton);
    
            JButton fiveButton = new JButton("5");
            panelButtons.add(fiveButton);
    
            JButton sixButton = new JButton("6");
            panelButtons.add(sixButton);
    
            JButton sevenButton = new JButton("7");
            panelButtons.add(sevenButton);
    
            JButton eightButton = new JButton("8");
            panelButtons.add(eightButton);
    
            JButton nineButton = new JButton("9");
            panelButtons.add(nineButton);
    
            //frame.getContentPane().add(new JSeparator(), BorderLayout.CENTER);
    
            // Add the buttons to the CENTER and they will
            // fill whatever space they are provided.
            gui.add(panelButtons, BorderLayout.CENTER);
            //frame.setBounds(50, 50, 500, 500);
            //frame.setResizable(false);
            frame.pack();
            frame.setVisible(true); 
        }    
    
        public static void main(String[] args) {    
           java.awt.EventQueue.invokeLater(new Runnable() {
    
             @Override
             public void run() {
                new Calculator();
             }
           });    
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a calculator on a page. Since it is not tabular
I'm trying to use the front-facing camera as a brightness sensor (there is no
I'm trying to make sure some data is auto-deleted when there's no more references
There is a thread that fills the db and I am trying to make
Is there anything similar to getElementById in actionscript? I'm trying to make a prototype
I'm trying to reorganize my code and make it more unobstrusive. Mainly, there is
I'm trying to make a simple GUI calculator in Python with Tkinter. However the
I am trying to make a calculator in C or Objective-C that accepts a
Hey I'm trying to make a clear button for my polish calculator.. code give
I am trying to make a calculator where a user can select from a

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.