/*
* CardLayoutDemo.java requires no other files.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class CardLayoutDemo implements ItemListener{
JPanel cards; //a panel that uses CardLayout
final static String BUTTONPANEL = "Main Menu";
final static String TEXTPANEL = "Choose Your Destenation";
final static String FamilyDetails = "Submit Your Family Details ";
final static String AddCombo = "Add/Remove Combo Box";
final static String UserReview = "Write A User Review";
private JComboBox combo;
private JTextField txtBox;
private ImageIcon image1;
private JLabel label1;
private ImageIcon image2;
private JLabel holiday;
public void addComponentToPane(Container pane) {
//Put the JComboBox in a JPanel to get a nicer look.
JPanel comboBoxPane = new JPanel(); //use FlowLayout
String comboBoxItems[] = { BUTTONPANEL, TEXTPANEL, FamilyDetails, AddCombo, UserReview };
JComboBox cb = new JComboBox(comboBoxItems);
cb.setEditable(false);
cb.addItemListener(this);
comboBoxPane.add(cb);
//Create the "cards".
JPanel card1 = new JPanel();
JLabel l20=new JLabel("Welcome to your hotel reservation app");
JLabel l21=new JLabel("Please use the following drop down menu to go to the required area");
card1.add(l20); card1.add(l21);
image1 = new ImageIcon(getClass().getResource("hotel342.jpg"));
label1=new JLabel(image1);
card1.add(label1);
card1.add(new JLabel("For more information or if you are having any trouble"));
card1.add(new JLabel("using this app please go to the following webpage"));
card1.add(new JLabel("www.tripadviser.com or call 617-670-6300"));
//
//
//CHoose your destination
final JPanel card2 = new JPanel();
card2.add(new JLabel("Please choose your destination based upon on the following list given."));
final JCheckBox show1, show2, show3, show4, show5, show6, show7, show8, show9, show10;
show1 = new JCheckBox("Would you like to go to Japan?");
card2.add(show1);
show2= new JCheckBox("Would you like to go to America?");
card2.add(show2);
show3= new JCheckBox("Would you like to go to Brazil?");
card2.add(show3);
show4= new JCheckBox("Would you like to go to Africa?");
card2.add(show4);
show5= new JCheckBox("Would you like to go to Barcelona?");
card2.add(show5);
show6= new JCheckBox("Would you like to go to China?");
card2.add(show6);
show7= new JCheckBox("Would you like to go to Canada?");
card2.add(show7);
show8= new JCheckBox("Would you like to go to France?");
card2.add(show8);
show9= new JCheckBox("Would you like to go to England?");
card2.add(show9);
show10= new JCheckBox("Would you like to go to Australia?");
card2.add(show10);
final JLabel label1=new JLabel();
card2.add(label1);
final JLabel label2=new JLabel();
card2.add(label2);
final JLabel label3=new JLabel();
card2.add(label3);
final JLabel label4=new JLabel();
card2.add(label4);
final JLabel label5=new JLabel();
card2.add(label5);
final JLabel label6=new JLabel();
card2.add(label6);
final JLabel label7=new JLabel();
card2.add(label7);
final JLabel label8=new JLabel();
card2.add(label8);
final JLabel label9=new JLabel();
card2.add(label9);
final JLabel label10=new JLabel();
card2.add(label10);
label1.setForeground(Color.RED);
label2.setForeground(Color.BLUE);
label3.setForeground(Color.GREEN);
label4.setForeground(Color.YELLOW);
label5.setForeground(Color.PINK);
label6.setForeground(Color.BLACK);
label7.setForeground(Color.ORANGE);
label8.setForeground(Color.GRAY);
label9.setForeground(Color.CYAN);
label10.setForeground(Color.MAGENTA);
label1.setBackground(Color.BLACK);
label1.setOpaque(true);
label2.setBackground(Color.BLACK);
label2.setOpaque(true);
label3.setBackground(Color.BLACK);
label3.setOpaque(true);
label4.setBackground(Color.BLACK);
label4.setOpaque(true);
label5.setBackground(Color.BLACK);
label5.setOpaque(true);
label6.setBackground(Color.WHITE);
label6.setOpaque(true);
label7.setBackground(Color.BLACK);
label7.setOpaque(true);
label8.setBackground(Color.BLACK);
label8.setOpaque(true);
label9.setBackground(Color.BLACK);
label9.setOpaque(true);
label10.setBackground(Color.BLACK);
label10.setOpaque(true);
JPanel season=new JPanel();
season.setBackground(Color.GREEN);
JLabel seasons=new JLabel("Please choose the season, in which you would like to travel");
Font f=new Font("Serif", Font.BOLD,14);
seasons.setFont(f);
seasons.setForeground(Color.BLUE);
JRadioButton spring=new JRadioButton("Spring Holiday");
JRadioButton summer=new JRadioButton("Summer Hoilday");
JRadioButton autumn=new JRadioButton("Autumn Holiday");
JRadioButton winter=new JRadioButton("Winter Holiday");
season.add(spring);
season.add(summer);
season.add(autumn);
season.add(winter);
card2.add(seasons);
card2.add(season);
show1.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label1.setText("You have choosen Japan as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label1.setVisible(true);
else
label1.setVisible(false);
}
}
);
show2.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label2.setText("You have choosen America as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label2.setVisible(true);
else
label2.setVisible(false);
}
}
);
show3.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label3.setText("You have choosen Brazil as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label3.setVisible(true);
else
label3.setVisible(false);
}
}
);
show4.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label4.setText("You have choosen Africa as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label4.setVisible(true);
else
label4.setVisible(false);
}
}
);
show5.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label5.setText("You have choosen Barcelona as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label5.setVisible(true);
else
label5.setVisible(false);
}
}
);
show6.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label6.setText("You have choosen China as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label6.setVisible(true);
else
label6.setVisible(false);
}
}
);
show7.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label7.setText("You have choosen Canada as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label7.setVisible(true);
else
label7.setVisible(false);
}
}
);
show8.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label8.setText("You have choosen France as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label8.setVisible(true);
else
label8.setVisible(false);
}
}
);
show9.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label9.setText("You have choosen England as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label9.setVisible(true);
else
label9.setVisible(false);
}
}
);
show10.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label10.setText("You have choosen Australia as your destination.");
if(e.getStateChange() == ItemEvent.SELECTED)
label10.setVisible(true);
else
label10.setVisible(false);
}
}
);
//end of chose your destination
//
//
//Submit your family details
JPanel card4 =new JPanel();
JPanel p10=new JPanel();
JPanel p11=new JPanel();
JPanel p12=new JPanel();
JPanel p13=new JPanel();
JPanel p14=new JPanel();
p10.setLayout(new GridLayout(6,2));
p11.setLayout(new GridLayout(4,1));
p12.setLayout(new GridLayout(2,2));
p14.setLayout(new GridLayout(3,2));
p11.setBackground(Color.YELLOW);
p13.setBackground(Color.BLUE);
JLabel manager=new JLabel("Please note, there must only one person in charge ");
JLabel manager1=new JLabel("of submitting the family details.");
JLabel manager2=new JLabel("However two numbers are required if the person managing ");
JLabel manager3=new JLabel("the information cannot be contacted.");
JLabel checkin=new JLabel("Family Check-in Date:");
JLabel checkout=new JLabel("Family Check-out Date:");
JLabel Name=new JLabel("Faimly Last Name:");
JLabel fName=new JLabel("First Name:");
JLabel Adults=new JLabel("Adults:>>>");
JLabel Children=new JLabel("Children:>>>");
String number[]={"1","2","3","4","5","6","7","8","9","10"};
JComboBox familynumber=new JComboBox(number);
String number1[]={"1","2","3","4","5","6","7","8","9","10"};
JComboBox childrenumber=new JComboBox(number1);
JTextField tf10=new JTextField("DD/MM/YYYY",5);
JTextField tf11=new JTextField("DD/MM/YYYY",5);
JTextField tf12=new JTextField(5);
JTextField tf13=new JTextField(5);
JButton submit=new JButton("Submit Your Information");
JLabel room=new JLabel("Please select the room type for your party:");
JRadioButton single=new JRadioButton("Single Room");
JRadioButton double1=new JRadioButton("Double Room");
JRadioButton ensuite=new JRadioButton("Ensuite Room");
JRadioButton familyr=new JRadioButton("Family Room");
JRadioButton firstc=new JRadioButton("First Class Room");
image2 = new ImageIcon(getClass().getResource("holiday.jpg"));
holiday=new JLabel(image2);
p11.add(manager);
p11.add(manager1);
p11.add(manager2);
p11.add(manager3);
p10.add(checkin); p10.add(tf10);
p10.add(checkout); p10.add(tf11);
p10.add(Name); p10.add(tf12);
p10.add(fName); p10.add(tf13);
p12.add(Adults); p12.add(familynumber);
p12.add(Children); p12.add(childrenumber);
p14.add(room);
p14.add(single); p14.add(double1);
p14.add(ensuite); p14.add(familyr); p14.add(firstc);
p13.add(submit);
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "Thank you for submitting your information", "Information", JOptionPane.INFORMATION_MESSAGE);
}
});
card4.add(p11);
card4.add(p10);
card4.add(p12);
card4.add(p14);
card4.add(p13);
card4.add(holiday);
//end of submit your family details
//
//
//Add/remove combo box
JPanel card3 =new JPanel();
String items[] = {"Honda", "Ford", "BMW", "Audi"};
combo = new JComboBox(items);
JButton button1 = new JButton("Add");
txtBox = new JTextField(20);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (!txtBox.getText().equals("")){
int a = 0;
for(int i = 0; i < combo.getItemCount(); i++){
if(combo.getItemAt(i).equals(txtBox.getText())){
a = 1;
break;
}
}
if (a == 1)
JOptionPane.showMessageDialog(null,"Combo has already this item.");
else
combo.addItem(txtBox.getText());
}
else{
JOptionPane.showMessageDialog(null,"Please enter text in Text Box");
}
}
});
JButton button2 = new JButton("Remove");
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (combo.getItemCount() > 0)
combo.removeItemAt(0);
else
JOptionPane.showMessageDialog(null,"Item not available");
}
});
card3.add(txtBox);
card3.add(combo);
card3.add(button1);
card3.add(button2);
//end of combo box
//
//
//Write a user review
JPanel card5 =new JPanel();
JPanel p21=new JPanel();
JPanel p22=new JPanel();
final JTextArea ta5=new JTextArea(16,16);
final JTextField tf6=new JTextField(10);
JButton send=new JButton("Send");
send.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ta5.setText(tf6.getText());
}
});
card5.add(ta5);
card5.add(tf6);
card5.add(send);
//end of write a user review
//
//
//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(card1, BUTTONPANEL);
cards.add(card2, TEXTPANEL);
cards.add(card3, AddCombo);
cards.add(card4, FamilyDetails);
cards.add(card5, UserReview);
pane.add(comboBoxPane, BorderLayout.PAGE_START);
pane.add(cards, BorderLayout.CENTER);
}
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout)(cards.getLayout());
cl.show(cards, (String)evt.getItem());
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Keith");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
CardLayoutDemo demo = new CardLayoutDemo();
demo.addComponentToPane(frame.getContentPane());
//Display the window.
frame.pack();
frame.setSize(500,700);
frame.setVisible(true);
}
public CardLayoutDemo() {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}