my homework problem Complete the code in the Practice class such that each time the user clicks the SUM button, the sum of the two valid integers will be shown in the lower right corner of the window (leave the user's input in the text fields). Here is a before and after view of the graphical user interface when the SUM button is clicked for the first time. 123 456 123 456 SUM SUM 579 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Practice { public static void main(String[] args) { JFrame frame = new JFrame("Add 2"); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); SumPanel panel = new SumPanel(); frame.getContentPane().add(panel); frame.setSize(140,80); frame.setVisible(true); } } class SumPanel extends JPanel { private JTextField op1Field; private JTextField op2Field; private JButton sumButton; private JLabel sumLabel; public SumPanel() { //Step 1; set up the layout setLayout(new GridLayout(2,2,4,4)); op1Field = new JTextField(); op2Field = new JTextField(); sumButton = new JButton("Sum"); sumLabel = newJLabel(); this.add(sumButton); this.add(op1Field); this.add(op2Field); this.add(sumButton); this.add(sumLabel); //Step3: Register the listener in the constructor //create a listener object from the following button listener class ????????????? //Register the button with its listener object ????????????? } //end of constructor SumPanel() //Step 2: Design a button listener class, implements the correct listener interface private class SumButtonListener implements ?????????? { public void action performed(ActionEvent e) { //handle the button event here ????????????? } }//end of SumButtonListener }//end of SumPanel class

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter8: Advanced Data Handling Concepts
Section: Chapter Questions
Problem 3GZ
icon
Related questions
Question

my homework problem

Complete the code in the Practice class such that each time the user clicks the SUM button, the sum of the two valid integers will be shown in the lower right corner of the window (leave the user's input in the text fields). Here is a before and after view of the graphical user interface when the SUM button is clicked for the first time.

123 456 123 456

SUM SUM 579

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Practice {

public static void main(String[] args) {

JFrame frame = new JFrame("Add 2");

frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);

SumPanel panel = new SumPanel();

frame.getContentPane().add(panel);

frame.setSize(140,80);

frame.setVisible(true);

}

}

class SumPanel extends JPanel {

private JTextField op1Field;

private JTextField op2Field;

private JButton sumButton;

private JLabel sumLabel;

public SumPanel() {

//Step 1; set up the layout

setLayout(new GridLayout(2,2,4,4));

op1Field = new JTextField();

op2Field = new JTextField();

sumButton = new JButton("Sum");

sumLabel = newJLabel();

this.add(sumButton);

this.add(op1Field);

this.add(op2Field);

this.add(sumButton);

this.add(sumLabel);

//Step3: Register the listener in the constructor

//create a listener object from the following button listener class

?????????????

//Register the button with its listener object

?????????????

} //end of constructor SumPanel()

//Step 2: Design a button listener class, implements the correct listener interface

private class SumButtonListener implements ?????????? {

public void action performed(ActionEvent e) {

//handle the button event here

?????????????

}

}//end of SumButtonListener

}//end of SumPanel class

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT