Advertisement
Guest User

CheckoutPanelGUI

a guest
Apr 26th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. package edu.occ.or.cis2151;
  2. import java.awt.BorderLayout;
  3. import java.text.DecimalFormat;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9.  
  10. public class CheckoutPanelGUI extends JFrame {
  11.  
  12. private CustomerProfile profile;
  13. private OilChangePanel oil;
  14. private MaintenancePanel maintenance;
  15. private JPanel buttonPanel;
  16. private JButton calcButton;
  17. private JButton exitButton;
  18. private JButton estimateButton;
  19. private final double TAX_RATE = 0.06;
  20.  
  21.  
  22. public CheckoutPanelGUI() {
  23.  
  24. // Title Display
  25. setTitle("Order Checkout");
  26.  
  27. // How the programs closes on the exit button
  28. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29.  
  30.  
  31. setLayout(new BorderLayout());
  32.  
  33. //creating custom panels
  34. profile = new CustomerProfile();
  35. oil = new OilChangePanel();
  36. maintenance = new MaintenancePanel();
  37.  
  38. //Creating components to the content of the window
  39. add(profile, BorderLayout.EAST);
  40. add(oil, BorderLayout.CENTER);
  41. add(maintenance, BorderLayout.WEST);
  42. add(buttonPanel, BorderLayout.SOUTH);
  43.  
  44. pack();
  45. setVisible(true);
  46. }
  47. private void buildButtonPanel() {
  48.  
  49. // Create a panel for the buttons.
  50. buttonPanel = new JPanel();
  51.  
  52. // Create the buttons.
  53. calcButton = new JButton("Calculate");
  54. estimateButton = new JButton("Estimate");
  55. exitButton = new JButton("Exit");
  56.  
  57. // Register the action listeners.
  58. calcButton.addActionListener(new CalcButtonListener());
  59. exitButton.addActionListener(new ExitButtonListener());
  60.  
  61. // Add the buttons to the button panel.
  62. buttonPanel.add(calcButton);
  63. buttonPanel.add(exitButton);
  64. }
  65.  
  66.  
  67. private class CalcButtonListener implements ActionListener
  68. {
  69. public void actionPerformed(ActionEvent e)
  70. {
  71. double subtotal, tax, total;
  72.  
  73. subtotal = oil.getOilCost() +
  74. maintenance.getMaintenanceCost();
  75.  
  76. tax = subtotal * TAX_RATE;
  77.  
  78. total = subtotal + tax;
  79.  
  80. DecimalFormat dollar = new DecimalFormat("0.00");
  81.  
  82. JOptionPane.showMessageDialog(null, "Subtotal: $" + dollar.format(subtotal) + "\n" + "Tax: $" + dollar.format(tax) + "\n" +
  83. "Total: $" + dollar.format(total));
  84.  
  85. }
  86. }
  87.  
  88. private class ExitButtonListener implements ActionListener
  89. {
  90. public void actionPerformed(ActionEvent e)
  91. {
  92. System.exit(0);
  93. }
  94. }
  95.  
  96. public static void main(String[] args)
  97. {
  98. new CheckoutPanelGUI();
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement