Tabs Tab 1 Component Panel 1 example essay topic

3,443 words
//Import Classes import java x. swing. ; import java x. swing. event. ; import java. at. ; import java. at. event. ; import java. until. ; //Class specifics for making Dollars and Cents import java. text. Number Format; //Begin the ATM public class mad extends JPanel implements Action Listener, Item Listener{ //Create Global variables and objects JButton Start, burger 1, burger 2, burger 3, button, next, add order, pay now, added it, remove ord, cc pay, ca pay, coke, sprite, drp, root, orange, ultra, large, medium, small, a mex, visa, mc, atm, back, take, insert; String total order, orders, ord 1, ord 2, ord 3, burg 1, burg 2, burg 3, lett, to ma, k etc, must, on, pick, che, tt price, coked, sprite d, drp d, root, orange, ultra d, large, medium d, small, cc num,'s, currency Out, bill, ; JTabbedPane tabbed Pane; JScrollPane panel 8 bt a; JPanel panel 8 t, panel 8 b, panel 8 bb, panel 8 bt; JTextArea welcome txt, order, t orders, receipt, bye; JTextField amt due; JCheckBox lettuce, tomato's, ketchup, mustard, onions, pickles, cheese; int c, l, t, k, m, o, p, order num, item, p type, ; double b price,'s price, st price, o 1 p, o 2 p, o 3 p, t price, currency, amt du, bill a, bill; //Array to hold the check boxes on condiment selection. int checks; //Create GUI public mad { //Make all variables 0 or equivalent. bill a = 0; bill = 0; c = (-1); l = -1; t = -1; k = -1; m = -1; o = -1; p = -1; burg 1 = '; burg 2 = '; burg 3 = '; lett = '; to ma = '; k etc = '; must = '; on = '; pick = '; che = '; orders = '; ultra d = '; large = '; medium d = '; small = '; sprite d = '; drp d = '; root = '; orange = '; coked = '; checks = new int [3] [7]; order num = 1; p type = 0; ord 1 = '; ord 2 = '; ord 3 = '; = +1; total order = '; //Image Icon icon = new Image Icon ('dummy. jpg'); //Main Tabbed PanetabbedPane = new JTabbedPane ; //Call components, The tabs //Tab 1 Component panel 1 = make Panel 1 ; tabbed Pane. addTab ('Welcome', null, panel 1, 'Welcome'); tabbed Pane. setSelectedIndex (0); //Tab 2 Component panel 2 = make Panel 2 ; tabbed Pane. addTab ('Burger Choice', null, panel 2, 'Burgers'); //Tab 3 Component panel 3 = make Panel 3 ; tabbed Pane. addTab ('Condiments', null, panel 3, 'Condiments'); //Tab 4 Component panel 4 = make Panel 4 ; tabbed Pane. addTab ('Drink', null, panel 4, 'Soda Fountain'); //Tab 5 Component panel 5 = make Panel 5 ; tabbed Pane. addTab ('Size', null, panel 5, 'Ultra Size?' ); //Tab 6 Component panel 6 = make Panel 6 ; tabbed Pane. addTab ('Confirm Order', null, panel 6, 'Confirm order'); //Tab 7 Component panel 7 = make Panel 7 ; tabbed Pane. addTab ('Pay Now', null, panel 7, 'Pay Now'); //Component panel 8 = make Panel 8 ; is called later, after the pay now button is pressed//Diable all panels to restrict user movement. tabbed Pane. setEnabledAt (1, false); tabbed Pane. setEnabledAt (2, false); tabbed Pane. setEnabledAt (3, false); tabbed Pane. setEnabledAt (4, false); tabbed Pane. setEnabledAt (5, false); tabbed Pane. setEnabledAt (6, false); //New Layout for the tabbed pane setLayout (new Grid Layout (1, 1) ); add (tabbed Pane); }//Component Builders //Tab 1 public Component make Panel 1 {//New JPanel and welcome text. JPanel panel 1 = new JPanel ; welcome txt = new JTextArea ('Welcome to Mc. Dowels' all new Burger ATM, please press the Begin button to start your order. ' ); welcome txt. setBorder (BorderFactory. createEmptyBorder (5, 5, 5, 5) ); //New Jbutton for begin Start = new JButton ('Begin your order'); Start. addActionListener (this); panel 1. add (Start); panel 1. add (welcome txt); //Box Layout, top to bottom. panel 1. setLayout (new Box Layout (panel 1, Box Layout. PAGE AXIS) ); return panel 1; }; //Tab 2 public Component make Panel 2 { JTextArea note = new JTextArea ('Please choose a Burger Combo Meal. n All choices come with a Medium Drink and Fries.

' ); JPanel panel 2 = new JPanel ; burger 1 = new JButton ('Hamburger'); burger 1. addActionListener (this); burger 2 = new JButton ('Double Hamburger'); burger 2. addActionListener (this); burger 3 = new JButton ('Veg i-Burger'); burger 3. addActionListener (this); panel 2. add (note); panel 2. add (burger 1); panel 2. add (burger 2); panel 2. add (burger 3); panel 2. setLayout (new Box Layout (panel 2, Box Layout. PAGE AXIS) ); return panel 2; }; //Tab 3 public Component make Panel 3 { JPanel panel 3 = new JPanel ; next = new JButton ('update'); next. addActionListener (this); //JCheckBox that can be listened to by Item Listener cheese = new JCheckBox ('Cheese'); ketchup = new JCheckBox ('Ketchup'); onions = new JCheckBox ('Onions'); pickles = new JCheckBox ('Pickles'); mustard = new JCheckBox ('Mustard'); lettuce = new JCheckBox ('Lettuce'); tomato's = new JCheckBox ('Tomatos'); cheese. addItemListener (this); ketchup. addItemListener (this); onions. addItemListener (this); pickles. addItemListener (this); mustard. addItemListener (this); lettuce. addItemListener (this); tomato's. addItemListener (this); panel 3. add (cheese); panel 3. add (ketchup); panel 3. add (onions); panel 3. add (pickles); panel 3. add (mustard); panel 3. add (lettuce); panel 3. add (tomato's); panel 3. add (next); panel 3. setLayout (new Box Layout (panel 3, Box Layout. PAGE AXIS) ); //Method Condiment Test, runs method to verify which Check boxes are checked for each order, //Data inside checks ; return panel 3; }; //Tab 4 public Component make Panel 4 { JPanel panel 4 = new JPanel ; coke = new JButton ('Coke'); coke. addActionListener (this); sprite = new JButton ('Sprite'); sprite. addActionListener (this); drp = new JButton ('Dr. Pepper'); drp. addActionListener (this); root = new JButton ('Root Beer'); root. addActionListener (this); orange = new JButton ('Orange Soda'); orange. addActionListener (this); panel 4. add (coke); panel 4. add (sprite); panel 4. add (drp); panel 4. add (root); panel 4. add (orange); panel 4. setLayout (new Box Layout (panel 4, Box Layout. PAGE AXIS) ); return panel 4; }; //Tab 5, public Component make Panel 5 { JPanel panel 5 = new JPanel ; ultra = new JButton ('Ultra (c) Size. +$0.39'); ultra. addActionListener (this); large = new JButton ('Large Size, +$0.29'); large. addActionListener (this); medium = new JButton ('Medium Size'); medium. addActionListener (this); small = new JButton ('Small Size, -$0.28'); small. addActionListener (this); panel 5. add (ultra); panel 5. add (large); panel 5. add (medium); panel 5. add (small); panel 5. setLayout (new Box Layout (panel 5, Box Layout. PAGE AXIS) ); return panel 5; }; //Tab 6 public Component make Panel 6 { JPanel panel 6 = new JPanel ; order = new JTextArea ; order. setBorder (BorderFactory. createEmptyBorder (5, 5, 5, 5) ); add order = new JButton ('Add Another Combo'); add order. addActionListener (this); pay now = new JButton ('Pay Now'); pay now. addActionListener (this); panel 6. add (order); panel 6. add (add order); panel 6. add (pay now); panel 6. setLayout (new Box Layout (panel 6, Box Layout.

PAGE AXIS) ); return panel 6; }; //Tab 7 public Component make Panel 7 { t orders = new JTextArea ; t orders. setText (total order); t orders. setBorder (BorderFactory. createEmptyBorder (5, 5, 5, 5) ); JPanel panel 7 l = new JPanel ; added it = new JButton ('Add / Edit Order'); remove ord = new JButton ('Remove Order'); added it. addActionListener (this); remove ord. addActionListener (this); cc pay = new JButton ('Credit Card'); cc pay. addActionListener (this); ca pay = new JButton ('Cash'); ca pay. addActionListener (this); panel 7 l. add (added it); panel 7 l. add (remove ord); panel 7 l. add (Box. createRigidArea (new Dimension (0,200) ) ); panel 7 l. add (cc pay); panel 7 l. add (ca pay); JScrollPane panel 7 r = new JScrollPane (t orders); JSplitPane panel 7 = new JSplitPane (JSplitPane. HORIZONTAL SPLIT, panel 7 l, panel 7 r); panel 7. setDividerLocation (120); panel 7. setDividerSize (0); return panel 7; }; //Tab 8, Has two different ways of building depending on information from the Action listener's// Code. The building takes place after the Cash or credit button is pressed. I then builds accordingly. public Component make Panel 8 { //Possible objects, added depending on PType, The pay selection amt due = new JTextField ; amt due. setText (' Amount due: '+ tt price+' '); visa = new JButton ('Visa'); visa. addActionListener (this); mc = new JButton ('Master Card'); mc. addActionListener (this); a mex = new JButton ('American Express'); a mex. addActionListener (this); atm = new JButton ('ATM Debit Card'); atm. addActionListener (this); back = new JButton ('Back'); back. addActionListener (this); receipt = new JTextArea ; receipt. setBorder (BorderFactory. createEmptyBorder (5, 5, 5, 5) ); panel 8 bb = new JPanel ; panel 8 bt = new JPanel ; panel 8 bt a = new JScrollPane (receipt); //Builds for credit cards, if (p type = = 1) { receipt. setText ('Order # '++'nn'+total order); //add buttons for major credit cards. Add Receipt and amount due panel 8 t = new JPanel ; panel 8 t. add (amt due); panel 8 t. add (visa); panel 8 t. add (mc); panel 8 t. add (a mex); panel 8 t. add (atm); panel 8 t. add (back); panel 8 bt. add (panel 8 bt a); bye = new JTextArea ; bye. setBorder (BorderFactory. createEmptyBorder (5, 5, 5, 5) ); bye. setText ('Thank You for eating at Mc Dowels. n'+ 'Please remember to take your receipt below, and wait for your number to be called... '); //Take receipt and return to start screen for new order. take = new JButton ('Take Receipt'); take. addActionListener (this); } //Builds for cash. else if (p type = = 2) { //Add Insert Cash, Receipt, and take receipt buttons. panel 8 t = new JPanel ; panel 8 t. add (amt due); insert = new JButton ('Insert Bill'); insert. addActionListener (this); panel 8 t. add (insert); panel 8 t. add (back); receipt. setText ('Order # '++'nn'+total order); panel 8 bt. add (panel 8 bt a); bye = new JTextArea ; bye. setBorder (BorderFactory. createEmptyBorder (5, 5, 5, 5) ); bye. setText ('Thank You for eating at Mc Dowels. n'+ 'Please remember to take your receipt below, and wait for your number to be called... '); take = new JButton ('Take Receipt'); take. addActionListener (this); }; //Set layout of this panel panel 8 bb. setLayout (new Box Layout (panel 8 bb, Box Layout.

PAGE AXIS) ); //Jsplitpane the two panels JSplitPane panel 8 b = new JSplitPane (JSplitPane. VERTICAL SPLIT, panel 8 bt a, panel 8 bb); panel 8 b. setDividerLocation (300); panel 8 b. setDividerSize (0); //Another JSplitPane, to make 3 panels in one windowJSplitPane panel 8 = new JSplitPane (JSplitPane. VERTICAL SPLIT, panel 8 t, panel 8 b); //Divider Locations in pixels panel 8. setDividerLocation (65); panel 8. setDividerSize (0); return panel 8; }; //Method to clear all the variables and objects. public void reset { c = (-1); bill a = 0; bill = 0; l = -1; t = -1; k = -1; m = -1; o = -1; p = -1; burg 1 = '; burg 2 = '; burg 3 = '; lett = '; to ma = '; k etc = '; must = '; on = '; pick = '; che = '; orders = '; ultra d = '; large = '; medium d = '; small = '; sprite d = '; drp d = '; root = '; orange = '; coked = '; order num = 1; p type = 0; ord 1 = '; ord 2 = '; ord 3 = '; o 1 p = 0; o 2 p = 0; o 3 p = 0; //Reset all the checks in condiments checks [0] [0] = 0; checks [0] [1] = 0; checks [0] [2] = 0; checks [0] [3] = 0; checks [0] [4] = 0; checks [0] [5] = 0; checks [0] [6] = 0; checks [1] [0] = 0; checks [1] [1] = 0; checks [1] [2] = 0; checks [1] [3] = 0; checks [1] [4] = 0; checks [1] [5] = 0; checks [1] [6] = 0; checks [2] [0] = 0; checks [2] [1] = 0; checks [2] [2] = 0; checks [2] [3] = 0; checks [2] [4] = 0; checks [2] [5] = 0; checks [2] [6] = 0; total order = '; tt price = '; = +1; rem tab (7); //Reset to the main screen by disabling. tabbed Pane. setEnabledAt (6, false); tabbed Pane. setEnabledAt (5, false); tabbed Pane. setEnabledAt (4, false); tabbed Pane. setEnabledAt (3, false); tabbed Pane. setEnabledAt (2, false); tabbed Pane. setEnabledAt (1, false); tabbed Pane. setEnabledAt (0, true); sets el (0); } //Method for the sets el call above, Moves to indicated tab. public void sets el (int num) {tabbed Pane. setSelectedIndex (num); }; //This method sets the limit on orders ordered at the ATM. public void {if (order num = = 3) {add order. setVisible (false); }else if (order num = = 2) {add order. setVisible (true); }else if (order num = = 1) {add order. setVisible (true); }else if (order num = 4) {add order. setVisible (false); }; }//Reads the checks array and selects the condiment's check boxes according to checks's data. public void { //Buried If else if statements to allow for different order number and combos. //Order number 4 corresponds to order number 1, This is done because the user needs to edit an order //however, The add order button if the order is 3 or greater, hence 4-6 is 1-3 in reality. if (order num = = 4) { //setSelected called by a 1 or a 0 in the checks for each condiment, and order number //checks [0] is order number 1. checks [0] [0-6] are the condiments variables for all condiments if (checks [0] [0] = = 1) {cheese. setSelected (true); } else if (checks [0] [0] = = 0) {cheese. setSelected (false); }; if (checks [0] [1] = = 1) {ketchup. setSelected (true); } else if (checks [0] [1] = = 0) {ketchup. setSelected (false); }; if (checks [0] [2] = = 1) {onions. setSelected (true); } else if (checks [0] [2] = = 0) {onions. setSelected (false); }; if (checks [0] [3] = = 1) {pickles. setSelected (true); } else if (checks [0] [3] = = 0) {pickles. setSelected (false); }; if (checks [0] [4] = = 1) {mustard. setSelected (true); } else if (checks [0] [4] = = 0) {mustard. setSelected (false); }; if (checks [0] [5] = = 1) {lettuce. setSelected (true); } else if (checks [0] [5] = = 0) {lettuce. setSelected (false); }; if (checks [0] [6] = = 1) {tomato's. setSelected (true); } else if (checks [0] [6] = = 0) {tomato's. setSelected (false); }; } else if (order num = = 5) { if (checks [1] [0] = = 1) {cheese. setSelected (true); } else if (checks [1] [0] = = 0) {cheese. setSelected (false); }; if (checks [1] [1] = = 1) {ketchup. setSelected (true); } else if (checks [1] [1] = = 0) {ketchup. setSelected (false); }; if (checks [1] [2] = = 1) {onions. setSelected (true); } else if (checks [1] [2] = = 0) {onions. setSelected (false); }; if (checks [1] [3] = = 1) {pickles. setSelected (true); } else if (checks [1] [3] = = 0) {pickles. setSelected (false); }; if (checks [1] [4] = = 1) {mustard. setSelected (true); } else if (checks [1] [4] = = 0) {mustard. setSelected (false); }; if (checks [1] [5] = = 1) {lettuce. setSelected (true); } else if (checks [1] [5] = = 0) {lettuce. setSelected (false); }; if (checks [1] [6] = = 1) {tomato's. setSelected (true); } else if (checks [1] [6] = = 0) {tomato's. setSelected (false); }; } else if (order num = = 6) { if (checks [2] [0] = = 1) {cheese. setSelected (true); } else if (checks [2] [0] = = 0) {cheese. setSelected (false); }; if (checks [2] [1] = = 1) {ketchup. setSelected (true); } else if (checks [2] [1] = = 0) {ketchup. setSelected (false); }; if (checks [2] [2] = = 1) {onions. setSelected (true); } else if (checks [2] [2] = = 0) {onions. setSelected (false); }; if (checks [2] [3] = = 1) {pickles. setSelected (true); } else if (checks [2] [3] = = 0) {pickles. setSelected (false); }; if (checks [2] [4] = = 1) {mustard. setSelected (true); } else if (checks [2] [4] = = 0) {mustard. setSelected (false); }; if (checks [2] [5] = = 1) {lettuce. setSelected (true); } else if (checks [2] [5] = = 0) {lettuce. setSelected (false); }; if (checks [2] [6] = = 1) {tomato's. setSelected (true); } else if (checks [2] [6] = = 0) {tomato's. setSelected (false); }; } else if (order num = = 1) { if (checks [0] [0] = = 1) {cheese. setSelected (true); } else if (checks [0] [0] = = 0) {cheese. setSelected (false); }; if (checks [0] [1] = = 1) {ketchup. setSelected (true); } else if (checks [0] [1] = = 0) {ketchup. setSelected (false); }; if (checks [0] [2] = = 1) {onions. setSelected (true); } else if (checks [0] [2] = = 0) {onions. setSelected (false); }; if (checks [0] [3] = = 1) {pickles. setSelected (true); } else if (checks [0] [3] = = 0) {pickles. setSelected (false); }; if (checks [0] [4] = = 1) {mustard. setSelected (true); } else if (checks [0] [4] = = 0) {mustard. setSelected (false); }; if (checks [0] [5] = = 1) {lettuce. setSelected (true); } else if (checks [0] [5] = = 0) {lettuce. setSelected (false); }; if (checks [0] [6] = = 1) {tomato's. setSelected (true); } else if (checks [0] [6] = = 0) {tomato's. setSelected (false); }; } else if (order num = = 2) { if (checks [1] [0] = = 1) {cheese. setSelected (true); } else if (checks [1] [0] = = 0) {cheese. setSelected (false); }; if (checks [1] [1] = = 1) {ketchup. setSelected (true); } else if (checks [1] [1] = = 0) {ketchup. setSelected (false); }; if (checks [1] [2] = = 1) {onions. setSelected (true); } else if (checks [1] [2] = = 0) {onions. setSelected (false); }; if (checks [1] [3] = = 1) {pickles. setSelected (true); } else if (checks [1] [3] = = 0) {pickles. setSelected (false); }; if (checks [1] [4] = = 1) {mustard. setSelected (true); } else if (checks [1] [4] = = 0) {mustard. setSelected (false); }; if (checks [1] [5] = = 1) {lettuce. setSelected (true); } else if (checks [1] [5] = = 0) {lettuce. setSelected (false); }; if (checks [1] [6] = = 1) {tomato's. setSelected (true); } else if (checks [1] [6] = = 0) {tomato's. setSelected (false); }; } else if (order num = = 3) { if (checks [2] [0] = = 1) {cheese. setSelected (true); } else if (checks [2] [0] = = 0) {cheese. setSelected (false); }; if (checks [2] [1] = = 1) {ketchup. setSelected (true); } else if (checks [2] [1] = = 0) {ketchup. setSelected (false); }; if (checks [2] [2] = = 1) {onions. setSelected (true); } else if (checks [2] [2] = = 0) {onions. setSelected (false); }; if (checks [2] [3] = = 1) {pickles. setSelected (true); } else if (checks [2] [3] = = 0) {pickles. setSelected (false); }; if (checks [2] [4] = = 1) {mustard. setSelected (true); } else if (checks [2] [4] = = 0) {mustard. setSelected (false); }; if (checks [2] [5] = = 1) {lettuce. setSelected (true); } else if (checks [2] [5] = = 0) {lettuce. setSelected (false); }; if (checks [2] [6] = = 1) {tomato's. setSelected (true); } else if (checks [2] [6] = = 0) {tomato's. setSelected (false); }; }}//Str ign create for the.

Creates as if 3 orders are there at all times, except 2 //orders may be nothing and have no visual or other effects to the order public void ordered {if (order num = 4) {item = order num -3; }else if (order num.