Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import java.awt.Font;
- import java.awt.Color;
- import javax.swing.JRadioButton;
- import javax.swing.JTextField;
- import javax.swing.JCheckBox;
- import java.awt.SystemColor;
- import javax.swing.JButton;
- import javax.swing.UIManager;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JList;
- import javax.swing.JComboBox;
- public class drinkselect extends JFrame {
- private JPanel contentPane;
- private JTextField totalPrice;
- private JTextField drinkPrice;
- private JTextField balanceField;
- private JTextField inputField;
- protected Object btn50cent;
- private int Pepsi;
- private int Sprite;
- private JLabel thanksLabel;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- drinkselect frame = new drinkselect();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public float totalCoin = 0;
- /**
- * Create the frame.
- */
- public drinkselect() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 702, 534);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblVendingMachine = new JLabel("Vending Machine");
- lblVendingMachine.setFont(new Font("Stencil Std", Font.BOLD | Font.ITALIC, 27));
- lblVendingMachine.setBounds(211, 10, 292, 36);
- contentPane.add(lblVendingMachine);
- JLabel lblNewLabel = new JLabel("Drinks :");
- lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblNewLabel.setBounds(78, 59, 57, 13);
- contentPane.add(lblNewLabel);
- JPanel drinkPanel = new JPanel();
- drinkPanel.setBackground(Color.LIGHT_GRAY);
- drinkPanel.setForeground(Color.BLACK);
- drinkPanel.setBounds(78, 82, 516, 177);
- contentPane.add(drinkPanel);
- drinkPanel.setLayout(null);
- JLabel lblCokePrice = new JLabel("RM 2.50");
- lblCokePrice.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblCokePrice.setBounds(134, 26, 64, 17);
- drinkPanel.add(lblCokePrice);
- JLabel lblPepsiPrice = new JLabel("RM 2.50");
- lblPepsiPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblPepsiPrice.setBounds(134, 82, 62, 13);
- drinkPanel.add(lblPepsiPrice);
- JLabel lblSpritePrice = new JLabel("RM 2.50");
- lblSpritePrice.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblSpritePrice.setBounds(134, 143, 64, 13);
- drinkPanel.add(lblSpritePrice);
- JLabel lbl100PlusPrice = new JLabel("RM 2.20");
- lbl100PlusPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
- lbl100PlusPrice.setBounds(320, 28, 62, 13);
- drinkPanel.add(lbl100PlusPrice);
- JLabel lblWaterPrice = new JLabel("RM 2.00");
- lblWaterPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblWaterPrice.setBounds(320, 82, 62, 13);
- drinkPanel.add(lblWaterPrice);
- JLabel lblKickapooPrice = new JLabel("RM 2.40");
- lblKickapooPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblKickapooPrice.setBounds(320, 143, 62, 13);
- drinkPanel.add(lblKickapooPrice);
- JPanel cokePanel = new JPanel();
- cokePanel.setBounds(34, 10, 90, 41);
- drinkPanel.add(cokePanel);
- cokePanel.setLayout(null);
- JLabel lblCoke = new JLabel("Coke");
- lblCoke.setFont(new Font("Tahoma", Font.BOLD, 13));
- lblCoke.setBounds(30, 10, 38, 21);
- cokePanel.add(lblCoke);
- JPanel pepsiPanel = new JPanel();
- pepsiPanel.setLayout(null);
- pepsiPanel.setBounds(34, 68, 90, 41);
- drinkPanel.add(pepsiPanel);
- JLabel lblPepsi = new JLabel("Pepsi");
- lblPepsi.setFont(new Font("Tahoma", Font.BOLD, 13));
- lblPepsi.setBounds(30, 10, 38, 21);
- pepsiPanel.add(lblPepsi);
- JPanel spritePanel = new JPanel();
- spritePanel.setLayout(null);
- spritePanel.setBounds(34, 127, 90, 41);
- drinkPanel.add(spritePanel);
- JLabel lblSprite = new JLabel("Sprite");
- lblSprite.setFont(new Font("Tahoma", Font.BOLD, 13));
- lblSprite.setBounds(25, 10, 39, 21);
- spritePanel.add(lblSprite);
- JPanel hundredplusPanel = new JPanel();
- hundredplusPanel.setLayout(null);
- hundredplusPanel.setBounds(392, 10, 90, 41);
- drinkPanel.add(hundredplusPanel);
- JLabel lblRootBeer = new JLabel("Root Beer");
- lblRootBeer.setFont(new Font("Tahoma", Font.BOLD, 13));
- lblRootBeer.setBounds(10, 10, 70, 21);
- hundredplusPanel.add(lblRootBeer);
- JPanel waterPanel = new JPanel();
- waterPanel.setLayout(null);
- waterPanel.setBounds(392, 68, 90, 41);
- drinkPanel.add(waterPanel);
- JLabel lblWater = new JLabel("Mineral Water");
- lblWater.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblWater.setBounds(0, 10, 90, 21);
- waterPanel.add(lblWater);
- JPanel kickapooPanel = new JPanel();
- kickapooPanel.setLayout(null);
- kickapooPanel.setBounds(392, 127, 90, 41);
- drinkPanel.add(kickapooPanel);
- JLabel lblKickapoo = new JLabel("Kickapoo");
- lblKickapoo.setFont(new Font("Tahoma", Font.BOLD, 13));
- lblKickapoo.setBounds(20, 10, 60, 21);
- kickapooPanel.add(lblKickapoo);
- JPanel panel_1 = new JPanel();
- panel_1.setBackground(Color.LIGHT_GRAY);
- panel_1.setBounds(29, 282, 635, 205);
- contentPane.add(panel_1);
- panel_1.setLayout(null);
- JPanel moneyPanel = new JPanel();
- moneyPanel.setBackground(Color.WHITE);
- moneyPanel.setBounds(10, 10, 308, 185);
- panel_1.add(moneyPanel);
- moneyPanel.setLayout(null);
- JLabel lblNewLabel_1 = new JLabel("Please select your drink :");
- lblNewLabel_1.setBounds(10, 10, 161, 13);
- moneyPanel.add(lblNewLabel_1);
- lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 12));
- JLabel lblNewLabel_2 = new JLabel("Your input");
- lblNewLabel_2.setBounds(111, 79, 68, 22);
- moneyPanel.add(lblNewLabel_2);
- lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 12));
- totalPrice = new JTextField();
- totalPrice.setBounds(97, 148, 103, 31);
- moneyPanel.add(totalPrice);
- totalPrice.setColumns(10);
- JList list = new JList();
- list.setBounds(93, 73, -39, -21);
- moneyPanel.add(list);
- //set up combo box
- JComboBox drinkcomboBox = new JComboBox();
- drinkcomboBox.addItem("Drinks");
- drinkcomboBox.addItem("Coke");
- drinkcomboBox.addItem("Pepsi");
- drinkcomboBox.addItem("Sprite");
- drinkcomboBox.addItem("Root Beer");
- drinkcomboBox.addItem("Mineral Water");
- drinkcomboBox.addItem("Kickapoo");
- moneyPanel.add(drinkcomboBox);
- drinkcomboBox.setBounds(10, 28, 125, 21);
- moneyPanel.add(drinkcomboBox);
- Object select1 = drinkcomboBox.getSelectedItem();
- if(e.getSource() == drinkcomboBox) {
- if (select1 == "") {
- totalPrice.setText("Drinks");
- } else if (select1.equals("Coke") {
- totalPrice.setText("RM"+Coke);
- } else if (select1 == "Pepsi") {
- totalPrice.setText("RM"+Pepsi);
- } else if (select1 == "Sprite") {
- totalPrice.setText("RM"+Sprite);
- } else if (select1 == " Root Beer") {
- totalPrice.setText("RM"+RootBeer);
- } else if (select1 == "Mineral Water") {
- totalPrice.setText("RM"+MineralWater);
- } else if (select1 == "Kickapoo") {
- totalPrice.setText("RM"+Kickapoo);
- }
- } else if(e.getSource() == btnEnter) {
- if (select1 == "Coke") {
- totalPrice.setText("RM"+Coke);
- if(totalCoin>=Coke) {
- balance=totalCoin-Coke;
- drinkPrice.setText("Change= RM"+balance);
- totalCoin=0;
- drinkPrice.setText("Total Coin= RM"+ totalCoin);
- thanksLabel.setText( "Thank You!" );
- balanceField.setText("Balance= RM"+balance);
- }else if(totalCoin>=Pepsi) {
- balance=totalCoin-Pepsi;
- drinkPrice.setText("Change= RM"+balance);
- totalCoin=0;
- drinkPrice.setText("Total Coin= RM"+ totalCoin);
- thanksLabel.setText( "Thank You!" );
- balanceField.setText("Balance= RM"+balance);
- }else if(totalCoin>=Sprite) {
- balance=totalCoin-Sprite;
- drinkPrice.setText("Change= RM"+balance);
- totalCoin=0;
- drinkPrice.setText("Total Coin= RM"+ totalCoin);
- thanksLabel.setText( "Thank You!" );
- balanceField.setText("Balance= RM"+balance);
- }else if(totalCoin>=RootBeer) {
- balance=totalCoin-RootBeer;
- drinkPrice.setText("Change= RM"+balance);
- totalCoin=0;
- drinkPrice.setText("Total Coin= RM"+ totalCoin);
- thanksLabel.setText( "Thank You!" );
- balanceField.setText("Balance= RM"+balance);
- }else if(totalCoin>=MineralWater) {
- balance=totalCoin-MineralWater;
- drinkPrice.setText("Change= RM"+balance);
- totalCoin=0;
- drinkPrice.setText("Total Coin= RM"+ totalCoin);
- thanksLabel.setText( "Thank You!" );
- balanceField.setText("Balance= RM"+balance);
- }else if(totalCoin>=Kickapoo) {
- balance=totalCoin-Kickapoo;
- drinkPrice.setText("Change= RM"+balance);
- totalCoin=0;
- drinkPrice.setText("Total Coin= RM"+ totalCoin);
- thanksLabel.setText( "Thank You!" );
- balanceField.setText("Balance= RM"+balance);
- }
- }
- JButton btnRM1 = new JButton("RM 1");
- btnRM1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == btnRM1) {
- totalCoin+=1.00;
- inputField.setText("RM "+ totalCoin);
- }
- else if(e.getSource() == btn50cent) {
- totalCoin+=0.50;
- inputField.setText("RM"+ totalCoin);
- }
- }
- });
- btnRM1.setBounds(174, 111, 74, 27);
- moneyPanel.add(btnRM1);
- btnRM1.setBackground(SystemColor.activeCaption);
- btnRM1.setFont(new Font("Tahoma", Font.BOLD, 10));
- JButton btn50cent = new JButton("50 cent");
- btn50cent.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == btn50cent) {
- totalCoin+=0.50;
- inputField.setText("RM "+ totalCoin);
- }
- else if(e.getSource() == btnRM1) {
- totalCoin+=1.00;
- inputField.setText("RM"+ totalCoin);
- }
- }
- });
- btn50cent.setBounds(61, 111, 74, 27);
- moneyPanel.add(btn50cent);
- btn50cent.setBackground(SystemColor.activeCaption);
- btn50cent.setFont(new Font("Tahoma", Font.BOLD, 10));
- drinkPrice = new JTextField();
- drinkPrice.setBounds(181, 24, 109, 30);
- moneyPanel.add(drinkPrice);
- drinkPrice.setColumns(10);
- JButton btnEnter = new JButton("Enter");
- btnEnter.setFont(new Font("Tahoma", Font.BOLD, 12));
- btnEnter.setBackground(SystemColor.activeCaption);
- btnEnter.setBounds(10, 149, 74, 27);
- moneyPanel.add(btnEnter);
- inputField = new JTextField();
- inputField.setBounds(181, 73, 109, 28);
- moneyPanel.add(inputField);
- inputField.setColumns(10);
- JPanel itemPanel = new JPanel();
- itemPanel.setBackground(Color.WHITE);
- itemPanel.setBounds(419, 10, 206, 185);
- panel_1.add(itemPanel);
- itemPanel.setLayout(null);
- JLabel lblNewLabel_3 = new JLabel("Output");
- lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblNewLabel_3.setBounds(77, 10, 47, 13);
- itemPanel.add(lblNewLabel_3);
- balanceField = new JTextField();
- balanceField.setColumns(10);
- balanceField.setBounds(94, 144, 102, 31);
- itemPanel.add(balanceField);
- JLabel lblYourBalance = new JLabel("Your balance");
- lblYourBalance.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblYourBalance.setBounds(6, 147, 78, 22);
- itemPanel.add(lblYourBalance);
- JLabel thanksLabel = new JLabel("");
- thanksLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
- thanksLabel.setBounds(35, 39, 145, 22);
- itemPanel.add(thanksLabel);
- JLabel lblNewLabel_5 = new JLabel("We serve it, you deserve it.");
- lblNewLabel_5.setFont(new Font("Sitka Display", Font.ITALIC, 14));
- lblNewLabel_5.setBounds(347, 43, 156, 13);
- contentPane.add(lblNewLabel_5);
- JButton btnAdmin = new JButton("ADMIN");
- btnAdmin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- new login().setVisible(true);
- }
- private void setVisible(boolean b) {
- // TODO Auto-generated method stub
- }
- });
- btnAdmin.setBackground(UIManager.getColor("Button.darkShadow"));
- btnAdmin.setFont(new Font("Tahoma", Font.BOLD, 13));
- btnAdmin.setBounds(593, 10, 85, 25);
- contentPane.add(btnAdmin);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement