import java.awt.*;
import java.awt.event.*;
import java.io.ObjectOutputStream.PutField;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
public class Items extends JApplet {
//Skipped Code
//LIST BOXES variables
//Create 3 arrays of Strings and 3 list boxes
private String[] sandwiches = {"Bacon and Turkey", "Cheese steak Melt",
"Veggie Lite", "The Works"};
private String[] kids = {"Stay Fit", "Breakfast Sub", "Roast Beef", "Little Sub"};
private String[] drinks = {"Fountain Sodas", "Vitamin Water", "Iced Tea", "Orange Juice"};
private JList jlstsandwiches = new JList(sandwiches);
private JList jlstkids = new JList(kids);
private JList jlstdrinks = new JList(drinks);
//Create 3 arrays of prices and 3 arrays of image icons
private double[] sandwichPrices = {5.75, 6.25, 5.95};
private double[] kidsPrices = {3.50, 2.99, 3.29};
private double[] drinksPrices = {2.05, 1.25, 1.50};
//COMBO BOXES variables
//Create 3 arrays of Strings and 3 combo boxes
private String[] feelings = {"Today I am...", "Feeling Happy",
"Feeling Strong", "Feeling Energetic"};
private String[] specials = {"Special Sandwiches", "Big Lance", "Pepe"};
private String[] specialDrinks = {"Special Drinks", "Lance's Shake", "Smooth It"};
private JComboBox jcbofeelings = new JComboBox(feelings);
private JComboBox jcbospecials = new JComboBox(specials);
private JComboBox jcbodrinks = new JComboBox(specialDrinks);
//Create 2 arrays of prices and 2 arrays of image icons
private double[] specialSandwichPrices = {0.0, 6.75, 7.25};
private double[] specialDrinksPrices = {0.0, 2.50, 2.99};
//Skipped Code
// ---------------------------------------------------------------------------------------
//REGISTER LISTENERS
jlstsandwiches.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jlstkids.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jlstdrinks.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//Skipped Code
//WEST PANEL
//Register listeners for list boxes' menus
jlstsandwiches.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e){
/***int[] indices = jlstsandwiches.getSelectedIndices();
int i;
for(i = 0; i < indices.length; i++){
jtfItemPrice.setText(String.valueOf(sandwichPrices[indices[i]]));
}*/
int index = 0;
index = jlstsandwiches.getSelectedIndex();
if (index < sandwiches.length){
jtfItemPrice.setText(String.format("%4.2f", sandwichPrices[index]));
}
}
});
jlstkids.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e){
/***int[] indices = jlstkids.getSelectedIndices();
int i;
for(i = 0; i < indices.length; i++){
jtfItemPrice.setText(String.valueOf(sandwichPrices[indices[i]]));
}*/
int index = 0;
index = jlstkids.getSelectedIndex();
if (index < kids.length){
jtfItemPrice.setText(String.format("%4.2f", kidsPrices[index]));
}
}
});
jlstdrinks.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e){
/***int[] indices = jlstdrinks.getSelectedIndices();
int i;
for(i = 0; i < indices.length; i++){
jtfItemPrice.setText(String.valueOf(sandwichPrices[indices[i]]));
}*/
int index = 0;
index = jlstdrinks.getSelectedIndex();
if (index < drinks.length){
jtfItemPrice.setText(String.format("%4.2f", drinksPrices[index]));
}
}
});
//NORTH PANEL
//Register listeners for combo boxes
jcbospecials.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e){
int index = 0;
index = jcbospecials.getSelectedIndex();
if (index < specials.length){
jtfItemPrice.setText(String.format("%4.2f", specialSandwichPrices[index]));
}
}
});
jcbodrinks.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e){
int index = 0;
if (index < specialDrinks.length){
index = jcbodrinks.getSelectedIndex();
jtfItemPrice.setText(String.format("%4.2f", specialDrinksPrices[index]));
}
}
});
}
}