Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java. How to add JButton that terminates program? package revenue; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Revenue extends JFrame { //GUI //Dimensions private

Java. How to add JButton that terminates program?

package revenue; import javax.swing.*; import java.awt.*; import java.awt.event.*;

public class Revenue extends JFrame { //GUI //Dimensions private final int Window_H = 400; private final int Window_W = 500; private JLabel a; //adult ticket private JLabel c; //child ticket private JLabel adult; //adult amount private JLabel child; //child amount private JLabel resultLabel; private JTextField c1; //child ticket price private JTextField a1; //adult ticket price private JTextField c2; //child amount private JTextField a2; //adult amount private JTextField GrossA; //Gross Adult Tickets private JTextField NetA; //Net Adult Tickets 20% private JTextField GrossC; //Gross Child Ticket private JTextField NetC; //Net Child Ticket private JTextField TotalGross; //Gross private JTextField TotalNet; //Net

private JPanel panel; private JButton calculate; private JButton reset; //Constructor public Revenue() { //Setting title and window size this.setTitle("Movie Theater Revenue Calculator"); this.setLayout(new BorderLayout()); this.setSize (Window_W, Window_H); this.setDefaultCloseOperation(EXIT_ON_CLOSE); buildPanel(); add(panel); pack(); setVisible(true); } public void buildPanel() { //Creating labels, text fields, building panel, calculating panel = new JPanel(); adult = new JLabel("How many adults are there?"); a2 = new JTextField(3); a = new JLabel("How much is one adult ticket?"); a1 = new JTextField(5); child = new JLabel("How many children are there?"); c2 = new JTextField(3); c = new JLabel("How much is one child ticket?"); c1 = new JTextField(5); calculate = new JButton("Calculate"); reset = new JButton("Reset"); //Adding ActionListener to buttons calculate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Calculating information String c = c1.getText(); //child ticket price double ChildAdmission = Double.parseDouble(c); String a = a1.getText(); //adult ticket price double AdultAdmission = Double.parseDouble(a); String NumOfChild = c2.getText(); //Number of children String NumOfAdults = a2.getText(); //Number of adults int child = Integer.parseInt(NumOfChild); int adult = Integer.parseInt(NumOfAdults); double GrossChild = child * ChildAdmission; double GrossAdult = adult * AdultAdmission; double gross = GrossChild + GrossAdult; double childnet = GrossChild * .2; double adultnet = GrossAdult * .2; double net = childnet + adultnet; } }); panel.add(child); panel.add(c2); panel.add(c); panel.add(c1); panel.add(adult); panel.add(a2); panel.add(a); panel.add(a1); panel.add(calculate); panel.add(reset); } public static void main(String[] args) { new Revenue(); } }

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_2

Step: 3

blur-text-image_3

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago