import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
public class ComboBoxDemo extends JFrame {
private double order = 0;
// Declare an array of Strings for flag titles
private String[] flagTitles = {"The Big Easy", "The Sophisticated Ensemble", "The Delectable"};
// Declare an ImageIcon array for the national flags of 9 countries
private ImageIcon[] flagImage = {
new ImageIcon("Images/bigeasy.jpg"),
new ImageIcon("Images/sophisticatedensemble.jpg"),
new ImageIcon("Images/thedelectable.jpg"),
};
// Declare an array of strings for flag descriptions
private String[] flagDescription = new String[3];
// Declare and create a description panel
private JTextPane Description = new JTextPane();
private JLabel flagImageLabel = new JLabel();
private JComboBox jcbo = new JComboBox(flagTitles);
// Create a combo box for selecting countries
public static void main(String[] args) {
ComboBoxDemo frame = new ComboBoxDemo();
frame.pack();
frame.setTitle("Modern Papyrus Cafe Menu");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public ComboBoxDemo() {
// Set text description
flagDescription[0] = "1: The Big Easy is, simply put, a big and easy meal!\n" +
"It consists of 1 hearty sandwich, stuffed with anything you want\n" +
"1 bag of crunchy and savory chips, of your choice\n" +
"and 1 large drink, all for $10.99!\n" +
"And we've got better news: you can also include any book you choose for 25% off,\n" +
"just for buying this meal!";
flagDescription[1] = "2: The Sophisticated Ensemble is for those that want to\n" +
"take delight in a warmer, sit-by-the-fire kind of meal. It contains:\n " +
"1 pastry, donut, brownie, or slice of cake\n" +
"and 1 coffee, latte, or tea, all for $8.99!\n" +
"To finalize the deal, you may add a book to your purchase for 15% off!";
flagDescription[2] = "3: The Delectable is for the sweet tooth! You may have\n" +
"1 milkshake, smoothie, or hot chocolate\n" +
"and 1 pastry, donut, brownie, or slice of cake, all for $7.99!\n" +
"To sweeten the deal, you may add a book to your purchase for 15% off!";
// Set the first country (Canada) for display
setDisplay(0);
Description.setText(flagDescription[0]);
flagImageLabel.setIcon(flagImage[0]);
Description.setPreferredSize(new Dimension(400,300));
flagImageLabel.setPreferredSize(new Dimension(300,200));
// Add combo box and description panel to the list
add(jcbo, BorderLayout.NORTH);
add(Description, BorderLayout.CENTER);
add(flagImageLabel, BorderLayout.WEST);
// Register listener
jcbo.addItemListener(new ItemListener() {
/** Handle item selection */
public void itemStateChanged(ItemEvent e) {
Description.setText(flagDescription[jcbo.getSelectedIndex()]);
flagImageLabel.setIcon(flagImage[jcbo.getSelectedIndex()]);
}
});
}
/** Set display information on the description panel */
public void setDisplay(int index) {
}
}