-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookHotel.java
237 lines (184 loc) · 7.26 KB
/
BookHotel.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package TravelingSystem;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class BookHotel extends JFrame implements ActionListener{
Choice chotel,cac,cfood;
JTextField tfpersons,tfdays;
String username;
JLabel labelusername,labelid,labelnumber,labelphone,labelprice;
JButton checkprice,bookpackage,back;
BookHotel(String username){
this.username=username;
setBounds(350,200,1100,600);
setLayout(null);
JLabel text=new JLabel("BOOK HOTELS");
text.setBounds(100,10,200,30);
text.setBackground(Color.WHITE);
text.setFont(new Font("Tahoma",Font.BOLD,20));
add(text);
JLabel lblusername=new JLabel("Username");
lblusername .setFont(new Font("Tahoma",Font.PLAIN,16));
lblusername.setBounds(40,70,200,20);
add(lblusername);
labelusername=new JLabel();
labelusername .setFont(new Font("Tahoma",Font.PLAIN,16));
labelusername.setBounds(250,70,100,20);
add(labelusername);
JLabel lblpackage=new JLabel("Select Hotel");
lblpackage .setFont(new Font("Tahoma",Font.PLAIN,16));
lblpackage.setBounds(40,110,200,20);
add(lblpackage);
chotel=new Choice();
chotel.setBounds(250,110,200,20);
add(chotel);
try{
Conn c=new Conn();
ResultSet rs=c.s.executeQuery("select *from hotel");
while(rs.next()){
chotel.add(rs.getString("name"));
}
}catch(Exception e){
e.printStackTrace();
}
JLabel lblpersons=new JLabel("Total Persons");
lblpersons .setFont(new Font("Tahoma",Font.PLAIN,16));
lblpersons.setBounds(40,150,200,25);
add(lblpersons);
tfpersons=new JTextField();
tfpersons.setBounds(250,150,200,25);
add(tfpersons);
JLabel lbldays=new JLabel("Number of Days");
lbldays .setFont(new Font("Tahoma",Font.PLAIN,16));
lbldays.setBounds(40,190,200,25);
add(lbldays);
tfdays=new JTextField();
tfdays.setBounds(250,190,200,25);
add(tfdays);
JLabel lblac=new JLabel("AC/NON-AC");
lblac .setFont(new Font("Tahoma",Font.PLAIN,16));
lblac.setBounds(40,230,200,25);
add(lblac);
cac=new Choice();
cac.add("AC");
cac.add("NON-AC");
cac.setBounds(250,230,200,20);
add(cac);
JLabel lblfood=new JLabel("Food Included");
lblfood .setFont(new Font("Tahoma",Font.PLAIN,16));
lblfood.setBounds(40,270,200,25);
add(lblfood);
cfood=new Choice();
cfood.add("Yes");
cfood.add("No");
cfood.setBounds(250,270,200,20);
add(cfood);
JLabel lblid=new JLabel("ID");
lblid .setFont(new Font("Tahoma",Font.PLAIN,16));
lblid.setBounds(40,310,200,20);
add(lblid);
labelid=new JLabel();
labelid.setBounds(250,310,200,25);
add(labelid);
JLabel lblnumber=new JLabel("Number");
lblnumber.setFont(new Font("Tahoma",Font.PLAIN,16));
lblnumber.setBounds(40,350,200,25);
add(lblnumber);
labelnumber=new JLabel();
labelnumber.setBounds(250,350,200,25);
add(labelnumber);
JLabel lblphone=new JLabel("Phone");
lblphone.setFont(new Font("Tahoma",Font.PLAIN,16));
lblphone.setBounds(40,390,200,25);
add(lblphone);
labelphone=new JLabel();
labelphone.setBounds(250,390,200,25);
add(labelphone);
JLabel lblprice=new JLabel("Total Price");
lblprice.setFont(new Font("Tahoma",Font.PLAIN,16));
lblprice.setBounds(40,430,200,25);
add(lblprice);
labelprice=new JLabel();
labelprice.setBounds(250,430,200,25);
add(labelprice);
try{
Conn c=new Conn();
String query="select *from customers where username = '"+username+"'";
ResultSet rs=c.s.executeQuery(query);
while(rs.next()){
labelusername.setText(rs.getString("username"));
labelid.setText(rs.getString("id"));
labelnumber.setText(rs.getString("number"));
labelphone.setText(rs.getString("phone"));
}
}catch(Exception e){
e.printStackTrace();
}
checkprice=new JButton("Check Price");
checkprice.setBackground(Color.BLACK);
checkprice.setForeground(Color.WHITE);
checkprice.setBounds(60,470,120,25);
checkprice.addActionListener(this);
add(checkprice);
bookpackage=new JButton("Book Hotel");
bookpackage.setBackground(Color.BLACK);
bookpackage.setForeground(Color.WHITE);
bookpackage.setBounds(200,470,120,25);
bookpackage.addActionListener(this);
add(bookpackage);
back=new JButton("Back ");
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
back.setBounds(370,470,120,25);
back.addActionListener(this);
add(back);
ImageIcon i1=new ImageIcon(ClassLoader.getSystemResource("icons/book.jpg"));
Image i2=i1.getImage().getScaledInstance(600,400,Image.SCALE_DEFAULT);
ImageIcon i3=new ImageIcon(i2);
JLabel l12=new JLabel(i3);
l12.setBounds(550,50,600,400);
add(l12);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==checkprice){
try{
Conn c=new Conn();
ResultSet rs=c.s.executeQuery("select *from hotel where name='"+chotel.getSelectedItem()+"'");
String pack= chotel.getSelectedItem();
int cost=0;
if(pack.equals("Gold Package")){
cost+=20000;
}else if(pack.equals("Silver Package")){
cost+=16000;
}else{
cost+=12000;
}
int persons=Integer.parseInt(tfpersons.getText());
cost *=persons;
labelprice.setText("Rs."+cost);
}catch(Exception e){
e.printStackTrace();
}
}
else if(ae.getSource()==bookpackage){
try{
Conn c=new Conn();
c.s.executeUpdate("insert into bookpackage values('"+labelusername.getText()+"','"+cpackage.getSelectedItem()+"','"+tfpersons.getText()+"','"+labelid.getText()+"','"+labelnumber.getText()+"','"+labelphone.getText()+"','"+labelprice.getText()+"')");
JOptionPane.showMessageDialog(null,"Package Booked Successfully" );
setVisible(false);
}catch(Exception e){
e.printStackTrace();
}
}
else{
setVisible(false);
}
}
public static void main(String [] args){
new BookHotel("Anshu123");
}
}
{
}