Commit ad14a0b2 authored by robert.sharp's avatar robert.sharp

Update temp.java

parent 15174f30
......@@ -9,10 +9,28 @@
* @author rober
*/
public class temp extends javax.swing.JFrame {
/**
* Creates new form temp
*/
static double price[]={2, 0.5, 1, 2, 1};
//the prices
static double quantity[]={20, 20, 20, 20, 20};
//the quantity of the items
static double ctrlquant[]={20, 20, 20, 20, 20};
//the maximum quantity of the items
static String itemCode[]={"01", "02", "03", "04", "05"};
//the code of the items
static String itemName[]={"Chocolate","Water","Drink", "Snack", "Sweet"};
//the names of the items
//setting the default values
static String ID = "";
static String Chosen = "";
static String Price = "";
public temp() {
initComponents();
}
......@@ -26,22 +44,112 @@ public class temp extends javax.swing.JFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
ItemSelect = new javax.swing.JPanel();
ItemSelectBox = new javax.swing.JComboBox<>();
jLabel1 = new javax.swing.JLabel();
PriceLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
ItemSelectBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Select Item", "Chocolate", "Water", "Drink", "Snack", "Sweet" }));
ItemSelectBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ItemSelectBoxActionPerformed(evt);
}
});
jLabel1.setText("Select Item Here:");
javax.swing.GroupLayout ItemSelectLayout = new javax.swing.GroupLayout(ItemSelect);
ItemSelect.setLayout(ItemSelectLayout);
ItemSelectLayout.setHorizontalGroup(
ItemSelectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(ItemSelectLayout.createSequentialGroup()
.addContainerGap()
.addGroup(ItemSelectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(ItemSelectLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(ItemSelectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ItemSelectLayout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(22, 22, 22))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ItemSelectLayout.createSequentialGroup()
.addComponent(ItemSelectBox, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
.addGroup(ItemSelectLayout.createSequentialGroup()
.addComponent(PriceLabel)
.addGap(0, 0, Short.MAX_VALUE))))
);
ItemSelectLayout.setVerticalGroup(
ItemSelectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(ItemSelectLayout.createSequentialGroup()
.addGap(51, 51, 51)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ItemSelectBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(PriceLabel)
.addContainerGap(30, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 279, Short.MAX_VALUE)
.addComponent(ItemSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(ItemSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 168, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void ItemSelectBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemSelectBoxActionPerformed
// TODO add your handling code here:
Chosen = ItemSelectBox.getSelectedItem().toString();
//gets the item selected
switch(Chosen){
//give the value of the item back
case "Chocolate":
Price = "£2";
ID = "01";
break;
case "Water":
Price = "£0.5";
ID = "02";
break;
case "Drink":
Price = "£1";
ID = "03";
break;
case "Snack":
Price = "£2";
ID = "04";
break;
case "Sweet":
Price = "£1";
ID = "05";
break;
default :
Price = "";
ID = "";
}
if (ID == ""){
PriceLabel.setText("Please selct an Item");
} else {
PriceLabel.setText("Price: " + Price);
}
//update price label
}//GEN-LAST:event_ItemSelectBoxActionPerformed
/**
* @param args the command line arguments
*/
......@@ -68,7 +176,6 @@ public class temp extends javax.swing.JFrame {
java.util.logging.Logger.getLogger(temp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
......@@ -78,6 +185,10 @@ public class temp extends javax.swing.JFrame {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel ItemSelect;
private javax.swing.JComboBox<String> ItemSelectBox;
private javax.swing.JLabel PriceLabel;
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}
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