Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

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
Check Mark
Knowledge Booster
Background pattern image
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
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education