Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help in Java: If you run the Adder.java (using javac Adder.java and then java Adder commands on the command line), you will see that when

Help in Java: If you run the Adder.java (using javac Adder.java and then java Adder commands on the command line), you will see that when the Calculate button is pressed, nothing happens. Add enough code to the AdderFrame.java class such that when the Calculate button is pressed, sum of the two integer numbers entered into the text fields is shown after the equal sign as demonstrated in the following image attached.

image text in transcribed

_____________________ Adder.java ___________ import javax.swing.JFrame;

public class Adder{ /** The main method creates an instance of the Adder class, which displays its window on the screen. */

public static void main(String[] args) { final int WINDOW_WIDTH = 520; // Window width final int WINDOW_HEIGHT = 100; // Window height AdderFrame adder = new AdderFrame(); // Specify what happens when the close button is clicked. adder.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set the size of the window. adder.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); // Display the window. adder.setVisible(true); } }

_____________________ AdderFrame.java ___________ import javax.swing.*; // Needed for Swing classes import java.awt.event.*; // Needed for ActionListener Interface

/** The AdderFrame class displays a JFrame that lets the user to add two integers */

public class AdderFrame extends JFrame { private JPanel panel; // To reference a panel private JLabel messageLabelAdd; // To reference a label private JLabel messageLabelequal; // To reference a label private JTextField firstNumber; // To reference a text field private JTextField secondNumber; // To reference a text field private JLabel result; private JButton calcButton; // To reference a button

/** Constructor */ public AdderFrame() { super("Integer Adder"); /** The buildPanel method adds a label, text field, and and a button to a panel. */ // Build the panel and add it to the frame. // Create a label to display instructions. messageLabelAdd = new JLabel(" + "); messageLabelequal = new JLabel(" = "); result = new JLabel(" 0 "); // Create two text fields 10 characters wide. firstNumber = new JTextField(10); secondNumber = new JTextField(10); // Create a button with the caption "Calculate". calcButton = new JButton("Calculate");

// Create a JPanel object and let the panel // field reference it. panel = new JPanel();

// Add the label, text field, and button // components to the panel. panel.add(firstNumber); panel.add(messageLabelAdd); panel.add(secondNumber); panel.add(messageLabelequal); panel.add(result); panel.add(calcButton);

// Add the panel to the frame's content pane. add(panel); } } ___________________________________

Integer Adder 120 = 175 calculat

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

=+Have you been arrested?

Answered: 1 week ago