Commit d9606378 authored by Tom's avatar Tom

Vending Machine Resit

parent 96e2943e
import javax.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class VendingMachineClass extends javax.swing.JFrame {
import java.awt.*;
import java.awt.event.*;
public class VendingMachineClass extends javax.swing.JFrame implements ActionListener{
public VendingMachineClass() {
initComponents();
}
private void initComponents() {
......@@ -27,7 +40,14 @@ public class VendingMachineClass extends javax.swing.JFrame {
jTextField3 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
//Here I am adding action listeners for each button, this allows me to add functionality to them.
jButton3.addActionListener(this);
jButton2.addActionListener(this);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { chocolate , water , hot_drink, snack, sweet }));
......@@ -38,11 +58,13 @@ public class VendingMachineClass extends javax.swing.JFrame {
jLabel1.setText("Selected Item");
jButton1.setText("Money Out");
jButton1.setText("Cost");
jButton2.setText("Money In");
jButton2.setText("Purchase");
jButton3.setText("Add");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
......@@ -96,7 +118,27 @@ public class VendingMachineClass extends javax.swing.JFrame {
pack();
}
//Here I create some variables
int cost = 0;
int stock = 20;
public void actionPerformed(ActionEvent e) {
//Checks which button has been clicked
if(e.getActionCommand().equals("Add")) {
//If the add button is clicked the item will be displayed in the following text areas.
jTextField1.setText(jComboBox1.getSelectedItem().toString());
jTextArea1.setText(jComboBox1.getSelectedItem().toString());
}
if(e.getActionCommand().equals("Cost")) {
System.out.print("Test");
}
}
public static void main(String args[]) {
try {
......@@ -121,10 +163,12 @@ public class VendingMachineClass extends javax.swing.JFrame {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VendingMachineClass().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
......@@ -138,3 +182,4 @@ public class VendingMachineClass extends javax.swing.JFrame {
private javax.swing.JTextField jTextField3;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment