- 分享
- 0
- 人气
- 0
- 主题
- 1
- 帖子
- 124
- UID
- 48182
- 积分
- 125
- 阅读权限
- 13
- 注册时间
- 2006-10-24
- 最后登录
- 2014-1-24
- 在线时间
- 263 小时
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TicketingSystem extends JFrame
{
JPanel ptop,btnPanel,p3,p4,p5,p6,p7,p8,pbtm,pleft,pBottom;
JLabel lblTitle,lblRsv,lblSeat,lblPref,lblRef,lblTime,lblDate,lblMov,lblTic,lblAva,lblRes;
JTextField tfRef;
JButton jbtn1,jbtn2,jbtn3,jbtn4,jbtn5,jbtn6,jbtn7,jbtn8,jbtn9,jbtn10,jbtn11,jbtn12,jbtn13,jbtn14,jbtn15;
JButton btnConfirm,btnReset,btnSeats;
JComboBox movieList , timeList , dateList;
String [] strMovie = {"Twilight", "Red Cliff", "Inkheart", "Alls Well Ends Well 2009", "Bride Wars", "The Wedding Game"};
String [] strTime = {"11.30AM", "12.30PM", "2.30PM", "3.45PM", "5.00PM", "7.30PM", "9.00PM"};
String [] strDate = {"8/2/2009", "9/2/2009", "10/2/2009", "11/2/2009", "12/2/2009", "13/2/2009", "14/2/2009"};
int ticketCount = 0;
String [] seatNo = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"};
String [] seat = new String [15];
public TicketingSystem()
{
setSize(500,400);
setTitle(" Roxy Theatres Online Ticketing System ");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// set layout for main frame
setLayout(new BorderLayout());
//Top Panel
JPanel ptop = new JPanel();
ptop.setLayout(new GridLayout(2,1));
Font f = new Font("Helvetica", Font.BOLD, 24);
lblTitle = new JLabel("Roxy Theatres - Online Ticketing System");
lblTitle.setFont(f);
lblTitle.setForeground(Color.GREEN);
ptop.add(lblTitle);
lblRsv = new JLabel(" Reserve seats by clicking on them! ");
ptop.add(lblRsv);
//button Panel
JPanel btnPanel = new JPanel();
btnPanel.setLayout(new GridLayout(3,5));
jbtn1 = new JButton("1");
jbtn1.setBackground(Color.BLUE);
jbtn1.addActionListener(new colorHandler());
jbtn2 = new JButton("2");
jbtn2.setBackground(Color.BLUE);
jbtn2.addActionListener(new colorHandler());
jbtn3 = new JButton("3");
jbtn3.setBackground(Color.BLUE);
jbtn3.addActionListener(new colorHandler());
jbtn4 = new JButton("4");
jbtn4.setBackground(Color.BLUE);
jbtn4.addActionListener(new colorHandler());
jbtn5 = new JButton("5");
jbtn5.setBackground(Color.BLUE);
jbtn5.addActionListener(new colorHandler());
jbtn6 = new JButton("6");
jbtn6.setBackground(Color.BLUE);
jbtn6.addActionListener(new colorHandler());
jbtn7 = new JButton("7");
jbtn7.setBackground(Color.BLUE);
jbtn7.addActionListener(new colorHandler());
jbtn8 = new JButton("8");
jbtn8.setBackground(Color.BLUE);
jbtn8.addActionListener(new colorHandler());
jbtn9 = new JButton("9");
jbtn9.setBackground(Color.BLUE);
jbtn9.addActionListener(new colorHandler());
jbtn10 = new JButton("10");
jbtn10.setBackground(Color.BLUE);
jbtn10.addActionListener(new colorHandler());
jbtn11 = new JButton("11");
jbtn11.setBackground(Color.BLUE);
jbtn11.addActionListener(new colorHandler());
jbtn12 = new JButton("12");
jbtn12.setBackground(Color.BLUE);
jbtn12.addActionListener(new colorHandler());
jbtn13 = new JButton("13");
jbtn13.setBackground(Color.BLUE);
jbtn13.addActionListener(new colorHandler());
jbtn14 = new JButton("14");
jbtn14.setBackground(Color.BLUE);
jbtn14.addActionListener(new colorHandler());
jbtn15 = new JButton("15");
jbtn15.setBackground(Color.BLUE);
jbtn15.addActionListener(new colorHandler());
//add button into button Panel
btnPanel.add(jbtn1);
btnPanel.add(jbtn2);
btnPanel.add(jbtn3);
btnPanel.add(jbtn4);
btnPanel.add(jbtn5);
btnPanel.add(jbtn6);
btnPanel.add(jbtn7);
btnPanel.add(jbtn8);
btnPanel.add(jbtn9);
btnPanel.add(jbtn10);
btnPanel.add(jbtn11);
btnPanel.add(jbtn12);
btnPanel.add(jbtn13);
btnPanel.add(jbtn14);
btnPanel.add(jbtn15);
//Panel 3
JPanel p3 = new JPanel();
p3.setLayout(new GridLayout(5,1));
lblSeat = new JLabel("Seats :");
lblAva = new JLabel("Available BLUE ");
lblAva.setForeground(Color.blue);
lblRes = new JLabel("Reseved RED ");
lblRes.setForeground(Color.red);
lblTic = new JLabel(" Price per ticket: $8.50($8 promo price for 3 or more) ");
lblPref = new JLabel(" Price per refreshment pack(Cok + Popcorn) $5.50 ");
//add label into Panel 3
p3.add(lblSeat);
p3.add(lblAva);
p3.add(lblRes);
p3.add(lblTic);
p3.add(lblPref);
//Panel 4
JPanel p4 = new JPanel();
p4.setLayout(new FlowLayout());
//add button into Panel 4
btnConfirm = new JButton("CONFIRM");
btnConfirm.addActionListener(new ConfirmHandler());
btnReset = new JButton("RESET");
btnReset.addActionListener(new ResetHandler());
p4.add(btnConfirm);
p4.add(btnReset);
//Panel 5
JPanel p5 = new JPanel();
p5.setLayout(new GridLayout(2,1));
lblRef = new JLabel(" How many refreshment packs? ");
tfRef = new JTextField(20);
//add label into Panel 5
p5.add(lblRef);
p5.add(tfRef);
//Panel 6
JPanel p6 = new JPanel();
p6.setLayout(new FlowLayout());
movieList = new JComboBox(strMovie);
lblMov = new JLabel("MovieList", JLabel.LEFT);
p6.add(lblMov);
p6.add(movieList);
//Panel 7
JPanel p7 = new JPanel();
p7.setLayout(new FlowLayout());
timeList = new JComboBox(strTime);
lblTime = new JLabel("TimeList", JLabel.LEFT);
p7.add(lblTime);
p7.add(timeList);
//Panel 8
JPanel p8 = new JPanel();
p8.setLayout(new FlowLayout());
dateList = new JComboBox(strDate);
lblDate = new JLabel("DateList", JLabel.LEFT);
p8.add(lblDate);
p8.add(dateList);
//Panel Left
JPanel pleft = new JPanel();
pleft.setLayout(new GridLayout(3,1));
pleft.add(p6);
pleft.add(p7);
pleft.add(p8);
//Bottom panel
pBottom = new JPanel();
pBottom.setLayout(new GridLayout(3,1));
pBottom.add(p3);
pBottom.add(p5);
pBottom.add(p4);
//add panel into layout
add(ptop, "North");
add(btnPanel, "Center");
add(pBottom, "South");
add(pleft, "West");
pack();
setVisible(true);
}
class colorHandler implements ActionListener
{
public void actionPerformed(ActionEvent evt){
JButton temButton = (JButton)evt.getSource();
if (temButton.getBackground()==Color.BLUE)
{
temButton.setBackground(Color.RED);
temButton.setEnabled(true);
}
else
{
temButton.setBackground(Color.BLUE);
}
}
} |
|