-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAirLineReservation.java
More file actions
148 lines (129 loc) · 5.31 KB
/
AirLineReservation.java
File metadata and controls
148 lines (129 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class AirLineReservation extends JPanel implements ActionListener {
String SelectedFlight;
JButton[] ButtonsA = new JButton[5];
JButton[] ButtonsB = new JButton[5];
JButton[] ButtonsC = new JButton[5];
JButton[] ButtonsD = new JButton[5];
JComboBox<String> Flights;
JLabel label;
String[] FlightNames = { "AUI22 London to Melbourne", "AUI33 Berlin to Texas", "AUI44 Moscow to Madrid" };
public void SetButtons(JButton[] Buttons, String s, int strtX, int strtY) {
for (int i = 0; i < Buttons.length; i++) {
Buttons[i] = new JButton((i + 1) + s);
Buttons[i].setBackground(Color.GREEN);
Buttons[i].setBounds(strtX + 150 * i, strtY, 60, 60);
Buttons[i].addActionListener(this);
this.add(Buttons[i]);
}
}
public AirLineReservation() {
SelectedFlight = "AUI22";
setLayout(null);
Flights = new JComboBox<String>(FlightNames);
Flights.setMaximumRowCount(3);
Flights.setBounds(700, 0, 225, 35);
Flights.setBackground(Color.WHITE);
Flights.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (((String) Flights.getSelectedItem()).equals("AUI22 London to Melbourne")) {
SelectedFlight = "AUI22";
buttonupdate(ButtonsA);
buttonupdate(ButtonsB);
buttonupdate(ButtonsC);
buttonupdate(ButtonsD);
} else if (((String) Flights.getSelectedItem()).equals("AUI33 Berlin to Texas")) {
SelectedFlight = "AUI33";
buttonupdate(ButtonsA);
buttonupdate(ButtonsB);
buttonupdate(ButtonsC);
buttonupdate(ButtonsD);
} else {
SelectedFlight = "AUI44";
buttonupdate(ButtonsA);
buttonupdate(ButtonsB);
buttonupdate(ButtonsC);
buttonupdate(ButtonsD);
}
}
});
add(Flights);
label = new JLabel("Flights:");
label.setBounds(630, 0, 200, 35);
add(label);
SetButtons(ButtonsA, "A", 500, 525);
SetButtons(ButtonsB, "B", 500, 450);
SetButtons(ButtonsC, "C", 500, 325);
SetButtons(ButtonsD, "D", 500, 250);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawArc(50, 200, 1000, 400, 90, 180);
g.drawLine(550, 200, 1400, 200);
g.drawLine(550, 600, 1400, 600);
g.drawLine(600, 200, 800, 100);
g.drawLine(850, 200, 950, 100);
g.drawLine(550, 600, 800, 700);
g.drawLine(850, 600, 950, 700);
}
public static void main(String[] args) {
JFrame frame = new JFrame("AUIS Airline Reservation System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AirLineReservation arc = new AirLineReservation();
frame.add(arc);
frame.setSize(1400, 925);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (((JButton) e.getSource()).getBackground() == Color.GREEN) {
((JButton) e.getSource()).setBackground(Color.RED);
DBupdate((JButton) e.getSource(), 1);
} else {
((JButton) e.getSource()).setBackground(Color.GREEN);
DBupdate((JButton) e.getSource(), 0);
}
}
public void buttonupdate(JButton[] button) {
for (int i = 0; i < button.length; i++) {
String buttonName = button[i].getText();
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/airlinereservationdb", "root", "omar");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select s_reserved from airlinereservationdb.seat WHERE s_number = '"
+ buttonName + "' AND f_code = '" + SelectedFlight + "';");
rs.next();
if ((Boolean) rs.getObject(1)) {
button[i].setBackground(Color.RED);
} else {
button[i].setBackground(Color.GREEN);
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
public void DBupdate(JButton button, int x) {
String buttonName = button.getText();
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/airlinereservationdb", "root", "omar");
System.out.println("connected");
Statement st = con.createStatement();
st.executeUpdate("UPDATE airlinereservationdb.seat SET s_Reserved = " + x + " WHERE s_number ='"
+ buttonName + "' and f_code = '" + SelectedFlight + "';");
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}