Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program based on a code given below using Java Programming Language. All details are on the second image at the very end of

Write a program based on a code given below using Java Programming Language. All details are on the second image at the very end of this post.

Code:

CalculatorGUI.java

import java.awt.BorderLayout;

import java.awt.Font;

import java.awt.GridLayout;

import javax.swing.*;

public class CalculatorGUI {

public static final String[][] BUTTON_TEXTS = {

{"7", "8", "9", "+"},

{"4", "5", "6", "-"},

{"1", "2", "3", "*"},

{"0", ".", "=", "/"}

};

public static final Font BTN_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 24);

private static void createAndShowGUI() {

JTextField field = new JTextField(15);

field.setFont(BTN_FONT.deriveFont(Font.PLAIN));

JPanel btnPanel = new JPanel(new GridLayout(BUTTON_TEXTS.length, BUTTON_TEXTS[0].length));

for (int i = 0; i

for (int j = 0; j

JButton btn = new JButton(BUTTON_TEXTS[i][j]);

btn.setFont(BTN_FONT);

btnPanel.add(btn);

}

}

JPanel mainPanel = new JPanel(new BorderLayout());

mainPanel.add(field, BorderLayout.PAGE_START);

mainPanel.add(btnPanel, BorderLayout.CENTER);

JFrame frame = new JFrame("Calculator");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(mainPanel);

frame.pack();

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

}

image text in transcribed

image text in transcribed

import java.awt.BorderLayout; import java.awt.Font; import java.awt.GridLayout; import javax.swing.*; public class CalculatorGUI public static final String 111 BUTTON TEXTS public static final Font BTN_FONT new Font (Font.SANS SERIF, Font.BOLD, 24); private static void createAndShowGUI() TextField field new JTextField(15); field.setFont (BTN_FONT.deriveFont (Font.PLAIN)); Panel btnPanel new JPanel (new GridLayout (BUTTON TEXTS.length, BUTTON TEXTS for (int i 0; ?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

3. You can gain power by making others feel important.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago