Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java package revenue; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * * @author */ public class Revenue extends JFrame { //GUI //Dimensions private final int

Java

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

/** * * @author */

public class Revenue extends JFrame { //GUI //Dimensions private final int Window_H = 400; private final int Window_W = 500; private JLabel a; private JLabel c; private JLabel adult; private JLabel child; private JTextField c1; private JTextField a1; private JTextField c2; private JTextField a2; private JPanel panel; private JButton calculate; private JButton reset; //Constructor public Revenue() { //Setting title and window size this.setTitle("Movie Theater Revenue Calculator"); 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) { String c = c1.getText(); double CHILD = Double.parseDouble(c); String a = a1.getText(); double ADULT = Double.parseDouble(a); String ch = c2.getText(); String ad = a2.getText(); int child = Integer.parseInt(ch); int adult = Integer.parseInt(ad); double childgross = child * CHILD; double adultgross = adult * ADULT; double gross = childgross + adultgross; double childnet = childgross; double adultnet = adultgross * .2; double net = childnet + adultnet; JOptionPane.showMessageDialog(null, gross); } }); 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(); } }

How can I display all these variables that came from the calculations in one text box? I seem to be having trouble getting it to work

double childgross = child * CHILD; double adultgross = adult * ADULT; double gross = childgross + adultgross; double childnet = childgross; double adultnet = adultgross * .2; double net = childnet + adultnet;

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

More Books

Students also viewed these Databases questions

Question

ANALYZE the emerging emphasis on employee recognition.

Answered: 1 week ago