View_Class

      1| /*
      2| NTC Java Programming 152-116
      3| Instructor: John Heckendorf
      4| Student: Jan Young & Keith Gallistel
      5| Lab ID: & 46314
      6| Project:pepsi.java
      7| */
      8| 
      9| import java.awt.*;
    10| import javax.swing.*;
    11| import javax.swing.border.*;
    12| 
    13| public class View_Class extends JFrame
    14| {
    15|     final static long serialVersionUID = 5;
    16| 
    17|     final int iBT = 9;
    18|     boolean bExact = false;
    19| 
    20|     //Layout
    21|     Container oContainer;
    22|     JPanel oJPEnterMoney;
    23|     JPanel oJPMarketing;
    24|     JPanel oJPTakeProduct;
    25|     JPanel oJPProduct;
    26| 
    27|     //Product Layout
    28|     GridLayout oGL1;
    29| 
    30|     //Objects
    31|     JLabel jlblImage;
    32|     JLabel jlblMoney;
    33|     JLabel jlblDisplay;
    34|     JTextField jtxtMoney;
    35|     JTextField jtxtMoneyDisplay;
    36|     JButton jbtnChangeBin;
    37|     JButton jbtnCancel;
    38|     JButton jbtnProductBin;
    39|     JRadioButton jrbnExactChange;
    40| 
    41|     //Soda Buttons
    42|     JButton[] oBT = new JButton[iBT];
    43|     String sBT[] = {"Pepsi-0", "Pepsi-1", "Pepsi-2", "Pepsi-3", "Diet Pepsi-4", "Mt. Dew-5", "Mt. Dew-6", "Diet Mt. Dew-7", "Aqua Fina-8"};
    44|     Color oDefault;
    45| 
    46|     public View_Class()
    47|     {
    48|         super("Pepsi Machine");
    49|         oContainer = getContentPane();
    50|         oContainer.setLayout(null);
    51| 
    52|         //Initialize methods
    53|         Initialize_Money_GUI();
    54|         Initialize_Display_GUI();
    55|         Initialize_Marketing_GUI();
    56|         Initialize_Take_Product_GUI();
    57|         Initialize_Product_Selection_GUI();
    58| 
    59|         setSize(640,500);
    60|         setVisible(true);
    61| 
    62|     }
    63| 
    64|     //Initialize Money GUI
    65|     private void Initialize_Money_GUI()
    66|     {
    67|         oJPEnterMoney = new JPanel();
    68|         oJPEnterMoney.setLayout(null);
    69|         oJPEnterMoney.setBorder(new BevelBorder(BevelBorder.RAISED));
    70| 
    71|         jlblMoney = new JLabel("Enter Money:");
    72|         jlblMoney.setBounds(7, 10, 85, 20);
    73|         oJPEnterMoney.add(jlblMoney);
    74| 
    75|         jtxtMoney = new JTextField(7);
    76|         jtxtMoney.setHorizontalAlignment(JTextField.RIGHT);
    77|         jtxtMoney.setBounds(97, 10, 85, 20);
    78|         oJPEnterMoney.add(jtxtMoney);
    79| 
    80|         Exact_Change_Random_Class oECRC = new Exact_Change_Random_Class();
    81|         bExact = oECRC.Rand_Exact(bExact);
    82| 
    83|         jrbnExactChange = new JRadioButton("Exact Change", bExact);
    84|         jrbnExactChange.setBounds(7, 32, 105, 20);
    85|         oJPEnterMoney.add(jrbnExactChange);
    86| 
    87|         oJPEnterMoney.setBounds(435, 3, 190, 60);
    88|         oContainer.add(oJPEnterMoney);
    89| 
    90|     }
    91| 
    92| //Initialize Display GUI
    93|     private void Initialize_Display_GUI()
    94|     {
    95|         oJPEnterMoney = new JPanel();
    96|         oJPEnterMoney.setLayout(null);
    97|         oJPEnterMoney.setBorder(new BevelBorder(BevelBorder.RAISED));
    98| 
    99|         jlblMoney = new JLabel("Money Display:");
  100|         jlblMoney.setBounds(7, 10, 85, 20);
  101|         oJPEnterMoney.add(jlblMoney);
  102|    103|         jtxtMoneyDisplay = new JTextField(7);
  104|         jtxtMoneyDisplay.setHorizontalAlignment(JTextField.RIGHT);
  105|         jtxtMoneyDisplay.setEditable(false);
  106|         jtxtMoneyDisplay.setBounds(97, 10, 85, 20);
  107|         oJPEnterMoney.add(jtxtMoneyDisplay);
  108| 
  109|         jbtnChangeBin = new JButton("Change");
  110|         jbtnChangeBin.setBounds(7, 35, 85, 20);
  111|         oJPEnterMoney.add(jbtnChangeBin);
  112| 
  113|         jbtnCancel = new JButton("Cancel");
  114|         jbtnCancel.setBounds(97, 35, 85, 20);
  115|         oJPEnterMoney.add(jbtnCancel);
  116| 
  117|         oDefault = jbtnCancel.getBackground();
  118| 
  119|         oJPEnterMoney.setBounds(435, 70, 190, 65);
  120|         oContainer.add(oJPEnterMoney);
  121| 
  122|     }
  123| 
  124|     //Initialize Marketing GUI
  125|     private void Initialize_Marketing_GUI()
  126|     {
  127|         oJPMarketing = new JPanel();
  128|         oJPMarketing.setLayout(null);
  129|         oJPMarketing.setBorder(new BevelBorder(BevelBorder.RAISED));
  130| 
  131|         Icon icoMarketImage = new ImageIcon(getClass().getResource("pepsi_grand.jpg"));
  132|         jlblImage = new JLabel(icoMarketImage);
  133|         jlblImage.setBounds(3,3,394,454);
  134|         oJPMarketing.add(jlblImage);
  135| 
  136|         oJPMarketing.setBounds(3, 3, 400, 460);
  137|         oContainer.add(oJPMarketing);
  138| 
  139|     }
  140| 
  141|     //Initialize Take Product GUI
  142|     private void Initialize_Take_Product_GUI()
  143|     {
  144|         oJPTakeProduct = new JPanel();
  145|         oJPTakeProduct.setLayout(null);
  146|         oJPTakeProduct.setBorder(new BevelBorder(BevelBorder.RAISED));
  147| 
  148|         jbtnProductBin = new JButton("Empty");
  149|         jbtnProductBin.setBounds(5, 5, 120, 30);
  150|         oJPTakeProduct.add(jbtnProductBin);
  151| 
  152|         oJPTakeProduct.setBounds(465, 400, 130, 40);
  153|         oContainer.add(oJPTakeProduct);
  154|     }
  155| 
  156|     //Initialize Product Selection GUI
  157|     private void Initialize_Product_Selection_GUI()
  158|     {
  159|         oJPProduct = new JPanel();
  160|         oGL1 = new GridLayout (9,1,5,5);
  161|         oJPProduct.setLayout(oGL1);
  162|         oJPProduct.setBorder(new BevelBorder(BevelBorder.RAISED));
  163| 
  164|         for(int x= 0; x < iBT; x++)
  165|         {
  166|             oBT[x] = new JButton(sBT[x]);
  167|             oBT[x].setHorizontalAlignment(SwingConstants.CENTER);
  168|             oJPProduct.add(oBT[x]);
  169|         }
  170| 
  171|         oJPProduct.setBounds(465, 150, 130, 240);
  172|         oContainer.add(oJPProduct);
  173|     }