Repository navigation
Expand file tree
/
Copy pathAddRoom.java
More file actions
162 lines (135 loc) · 5.5 KB
/
Copy pathAddRoom.java
File metadata and controls
162 lines (135 loc) · 5.5 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package Hotel.Management.System;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
public class AddRoom extends JFrame implements ActionListener {
JTextField t2, t4;
JComboBox<String> t3, t5, t6;
JButton b1, b2;
AddRoom() {
JPanel panel = new JPanel();
panel.setBounds(5, 5, 875, 490);
panel.setBackground(new Color(3, 45, 48));
panel.setLayout(null);
add(panel);
JLabel l1 = new JLabel("Add Rooms");
l1.setBounds(194, 10, 160, 22);
l1.setFont(new Font("Tahoma", Font.BOLD, 22));
l1.setForeground(Color.WHITE);
panel.add(l1);
JLabel l2 = new JLabel("Room Number");
l2.setBounds(64, 70, 152, 22);
l2.setFont(new Font("Tahoma", Font.BOLD, 14));
l2.setForeground(Color.WHITE);
panel.add(l2);
t2 = new JTextField();
t2.setBounds(200, 70, 156, 20);
t2.setFont(new Font("Tahoma", Font.PLAIN, 14));
t2.setForeground(Color.WHITE);
t2.setBackground(new Color(16, 108, 115));
panel.add(t2);
JLabel l3 = new JLabel("Availability");
l3.setBounds(64, 110, 152, 22);
l3.setFont(new Font("Tahoma", Font.BOLD, 14));
l3.setForeground(Color.WHITE);
panel.add(l3);
t3 = new JComboBox<>(new String[]{"Available", "Occupied"});
t3.setBounds(200, 110, 156, 20);
t3.setFont(new Font("Tahoma", Font.PLAIN, 14));
t3.setForeground(Color.WHITE);
t3.setBackground(new Color(16, 108, 115));
panel.add(t3);
JLabel l4 = new JLabel("Price");
l4.setBounds(64, 150, 152, 22);
l4.setFont(new Font("Tahoma", Font.BOLD, 14));
l4.setForeground(Color.WHITE);
panel.add(l4);
t4 = new JTextField();
t4.setBounds(200, 150, 156, 20);
t4.setFont(new Font("Tahoma", Font.PLAIN, 14));
t4.setForeground(Color.WHITE);
t4.setBackground(new Color(16, 108, 115));
panel.add(t4);
JLabel l5 = new JLabel("Cleaning Status");
l5.setBounds(64, 190, 152, 22);
l5.setFont(new Font("Tahoma", Font.BOLD, 14));
l5.setForeground(Color.WHITE);
panel.add(l5);
t5 = new JComboBox<>(new String[]{"Cleaned", "Dirty"});
t5.setBounds(200, 190, 156, 20);
t5.setFont(new Font("Tahoma", Font.PLAIN, 14));
t5.setForeground(Color.WHITE);
t5.setBackground(new Color(16, 108, 115));
panel.add(t5);
JLabel l6 = new JLabel("Bed Type");
l6.setBounds(64, 230, 152, 22);
l6.setFont(new Font("Tahoma", Font.BOLD, 14));
l6.setForeground(Color.WHITE);
panel.add(l6);
t6 = new JComboBox<>(new String[]{"Single Bed", "Double Bed"});
t6.setBounds(200, 230, 156, 20);
t6.setFont(new Font("Tahoma", Font.PLAIN, 14));
t6.setForeground(Color.WHITE);
t6.setBackground(new Color(16, 108, 115));
panel.add(t6);
b1 = new JButton("Add");
b1.setBounds(64, 321, 111, 33);
b1.setBackground(Color.BLACK);
b1.setForeground(Color.WHITE);
b1.addActionListener(this);
panel.add(b1);
b2 = new JButton("Back");
b2.setBounds(198, 321, 111, 33);
b2.setBackground(Color.BLACK);
b2.setForeground(Color.WHITE);
b2.addActionListener(this);
panel.add(b2);
ImageIcon imageIcon = new ImageIcon(ClassLoader.getSystemResource("icon/roomser.png"));
Image image = imageIcon.getImage().getScaledInstance(300, 300, Image.SCALE_DEFAULT);
JLabel label = new JLabel(new ImageIcon(image));
label.setBounds(500, 60, 300, 300);
panel.add(label);
setUndecorated(true);
setLocation(20, 200);
setLayout(null);
setSize(885, 500);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1) {
try {
connection c = new connection(); // your connection class
String room = t2.getText();
String ava = (String) t3.getSelectedItem();
String status = (String) t5.getSelectedItem();
String priceStr = t4.getText();
String type = (String) t6.getSelectedItem();
if (!priceStr.matches("\\d+")) {
JOptionPane.showMessageDialog(null, "Enter a valid number for Price");
return;
}
int price = Integer.parseInt(priceStr);
String query = "INSERT INTO Room (RoomNumber, Ava, Price, CleaningStatus, BedType) VALUES (?, ?, ?, ?, ?)";
PreparedStatement pst = c.connection.prepareStatement(query);
pst.setString(1, room);
pst.setString(2, ava);
pst.setInt(3, price);
pst.setString(4, status);
pst.setString(5, type);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Room Successfully Added");
setVisible(false);
} catch (Exception E) {
E.printStackTrace();
}
} else if (e.getSource() == b2) {
setVisible(false);
}
}
public static void main(String[] args) {
new AddRoom();
}
}