Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.occ.or.cis2151;
- import java.awt.BorderLayout;
- import java.text.DecimalFormat;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class CheckoutPanelGUI extends JFrame {
- private CustomerProfile profile;
- private OilChangePanel oil;
- private MaintenancePanel maintenance;
- private JPanel buttonPanel;
- private JButton calcButton;
- private JButton exitButton;
- private JButton estimateButton;
- private final double TAX_RATE = 0.06;
- public CheckoutPanelGUI() {
- // Title Display
- setTitle("Order Checkout");
- // How the programs closes on the exit button
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLayout(new BorderLayout());
- //creating custom panels
- profile = new CustomerProfile();
- oil = new OilChangePanel();
- maintenance = new MaintenancePanel();
- //Creating components to the content of the window
- add(profile, BorderLayout.EAST);
- add(oil, BorderLayout.CENTER);
- add(maintenance, BorderLayout.WEST);
- add(buttonPanel, BorderLayout.SOUTH);
- pack();
- setVisible(true);
- }
- private void buildButtonPanel() {
- // Create a panel for the buttons.
- buttonPanel = new JPanel();
- // Create the buttons.
- calcButton = new JButton("Calculate");
- estimateButton = new JButton("Estimate");
- exitButton = new JButton("Exit");
- // Register the action listeners.
- calcButton.addActionListener(new CalcButtonListener());
- exitButton.addActionListener(new ExitButtonListener());
- // Add the buttons to the button panel.
- buttonPanel.add(calcButton);
- buttonPanel.add(exitButton);
- }
- private class CalcButtonListener implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- double subtotal, tax, total;
- subtotal = oil.getOilCost() +
- maintenance.getMaintenanceCost();
- tax = subtotal * TAX_RATE;
- total = subtotal + tax;
- DecimalFormat dollar = new DecimalFormat("0.00");
- JOptionPane.showMessageDialog(null, "Subtotal: $" + dollar.format(subtotal) + "\n" + "Tax: $" + dollar.format(tax) + "\n" +
- "Total: $" + dollar.format(total));
- }
- }
- private class ExitButtonListener implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- System.exit(0);
- }
- }
- public static void main(String[] args)
- {
- new CheckoutPanelGUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement