import java.awt.*;
public class VendingMachine extends Panel //Applet implements ActionListener
{
public static int Cd_count = 20; // Stock with 5 quantities of products each
public static int Floopy_count = 20;
public static Label Amount; // Declare lMessage Label
public static Label Cdstock;
public static Label Floopystock;
public void Stock ()
{
setLayout (new GridLayout (4, 1));
setBackground (Color.yellow);
Cdstock = new Label ("Cd Stock = " + Cd_count); // Stock Quantities Label
Floopystock = new Label ("Floopy Stock = " + Floopy_count);
Amount = new Label ("*****Total Amount****");
Amount.setAlignment (Label.CENTER);
Amount.setBackground (Color.blue);
Amount.setForeground (Color.white);
add (Amount);
add (Cdstock);
add (Floopystock);
} // end of Pstock method
public static Button Cd; // Declare product selection button
public static Button Floopy;
// Creat labels for three product's names
public static Label lCd = new Label ("Cd"),
lFloopy = new Label ("Floopy");
public static Label Price1 = new Label ("$1.50"), // Creat labels for product's price
Price2 = new Label ("$1.00");
public static Label Name = new Label ("Daniel's Vending Machine"); // Creat new label
public static Label Message = new Label ("****Display Message****");
public void Product ()
{
setLayout (new BorderLayout ());
Panel pHolding = new Panel (); // Creat a panel to hold product selections
pHolding.setLayout (new GridLayout (3, 3)); // Ensure panel's layout 3 columns and 3 rows
pHolding.setBackground (Color.red); // Background = red
pHolding.setForeground (Color.blue); // Foreground = blue
lCd.setAlignment (Label.CENTER); // All Label Alignment - Center
lFloopy.setAlignment (Label.CENTER);
Price1.setAlignment (Label.CENTER);
Price2.setAlignment (Label.CENTER);
Name.setAlignment (Label.CENTER);
Message.setAlignment (Label.CENTER);
Message.setBackground (Color.pink);
pHolding.add (lCd); // Add 1st product's name, price & button
pHolding.add (Price1);
Cd = new Button ("A");
pHolding.add (Cd);
pHolding.add (lFloopy); // Add 2nd product's name, price & button
pHolding.add (Price2);
Floopy = new Button ("B");
pHolding.add (Floopy);
add ("North", Name);
add ("Center", pHolding);
add ("South", Message);
} // Pselection
public static Button Dollar; // Declare money function button
public static Button Quarter;
public static Button Dime;
public static Button Nickel;
public static Button Penny;
public void Money ()
{
setLayout (new GridLayout (4, 1)); // Ensure 1 column & 4 row
Dollar = new Button ("Dollar");
Quarter = new Button ("Quarter");
Dime = new Button ("Dime");
Nickel = new Button ("Nickel");
Penny = new Button ("Penny");
add (Dollar); // add 4 Buttons
add (Quarter);
add (Dime);
add (Nickel);
add (Penny);
} // end of Pmoney method
public static Button Cancel; // Declare Cancel and Accept button
public static Button Change;
public void Function ()
{
Change = new Button ("Change"); // Creat new button
Cancel = new Button ("Cancel"); // Creat new button
add (Change); // Add bAccept on pControl
add (Cancel); // Add bCancel on pControl
setForeground (Color.black); // Foregrond Color = black
} // Pmoney method
} // Pmoney method
|