-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeat_Check.java
145 lines (119 loc) · 4.03 KB
/
Seat_Check.java
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
package oodp;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Seat_Check extends JPanel implements ActionListener{
public Seat_Check()
{
int i,j,available=0;
setLayout(null);
JPanel panel_1=new JPanel();
panel_1.setLayout(null);
panel_1.setBounds(190, 40, 260, 200);
JPanel panel_2=new JPanel();
panel_2.setLayout(null);
panel_2.setBounds(190, 280, 260, 200);
try
{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "bitnami");
stmt=conn.createStatement();
}
catch(Exception exc){}
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
try
{
ResultSet re=stmt.executeQuery("SELECT * FROM seats WHERE x="+i+" AND y="+j+";");
while(re.next())
{
available=re.getInt("available");
}
}
catch(Exception exc){}
button=new JButton();
button.setBounds(10+62*(j-1),10+48*(i-1),52,38);
if(available==0)
button.setText("O");
else
button.setText("X");
button.setActionCommand(""+i+j);
button.addActionListener(this);
panel_1.add(button);
}
}
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
try
{
ResultSet re=stmt.executeQuery("SELECT * FROM seats WHERE x="+(i+4)+" AND y="+j+";");
while(re.next())
{
available=re.getInt("available");
}
}
catch(Exception exc){}
button=new JButton();
button.setBounds(10+62*(j-1),10+48*(i-1),52,38);
if(available==0)
button.setText("O");
else
button.setText("X");
button.setActionCommand(""+(i+4)+j);
button.addActionListener(this);
panel_2.add(button);
}
}
add(panel_1);
add(panel_2);
}
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
JButton event=(JButton)e.getSource();
if(command.length()==2)
{
String x=command.substring(0, 1);
String y=command.substring(1);
try
{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "bitnami");
stmt=conn.createStatement();
ResultSet re=stmt.executeQuery("SELECT * FROM seats WHERE x="+x+" AND y="+y+";");
while(re.next())
{
if(re.getInt("available")==0)
{
stmt.executeUpdate("Update seats SET x="+x+",y="+y+",available=1 WHERE x="+x+" AND y="+y+";");
event.setText("X");
JOptionPane.showMessageDialog(null, "예약 되었습니다.");
}
else
{
stmt.executeUpdate("Update seats SET x="+x+",y="+y+",available=0 WHERE x="+x+" AND y="+y+";");
event.setText("O");
JOptionPane.showMessageDialog(null, "예약이 취소 되었습니다.");
}
}
}
catch(Exception exc){}
}
else
{
MainBoard.board.remove(MainBoard.board_panel);
MainBoard.board.repaint();
MainBoard.board.revalidate();
MainBoard.board_panel=this;
MainBoard.board_panel.setBackground(Color.white);
MainBoard.board_panel.setBounds(150,40,650,560);
MainBoard.board.add(MainBoard.board_panel);
}
}
private JButton button;
private static Connection conn;
private static Statement stmt;
}