-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDepartment.java
More file actions
84 lines (72 loc) · 2.67 KB
/
Copy pathDepartment.java
File metadata and controls
84 lines (72 loc) · 2.67 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
package Hotel.Management.System;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.table.DefaultTableModel;
public class Department extends JFrame {
Department() {
JPanel panel = new JPanel();
panel.setBackground(new Color(3, 45, 48));
panel.setBounds(5, 5, 690, 490);
panel.setLayout(null);
add(panel);
JTable table = new JTable();
table.setBounds(0, 40, 700, 350);
table.setBackground(new Color(4, 45, 48));
table.setForeground(Color.WHITE);
panel.add(table);
// --- DATABASE CONNECTION FIX ---
try {
Connection c = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/HotelMS", "chirayu", "chirayu");
Statement stmt = c.createStatement();
String departmentInfo = "SELECT * FROM department";
ResultSet resultSet = stmt.executeQuery(departmentInfo);
DefaultTableModel model = new DefaultTableModel(
new Object[]{"Department", "Budget"}, 0);
while (resultSet.next()) {
model.addRow(new Object[]{
resultSet.getString("Department"),
resultSet.getInt("Budget")
});
}
table.setModel(model);
} catch (Exception e) {
e.printStackTrace();
}
JButton back = new JButton("BACK");
back.setBounds(400, 410, 120, 30);
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
panel.add(back);
back.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
JLabel label1 = new JLabel("Department");
label1.setBounds(145, 11, 105, 20);
label1.setForeground(Color.WHITE);
label1.setFont(new Font("Tahoma", Font.BOLD, 14));
panel.add(label1);
JLabel label2 = new JLabel("Budget");
label2.setBounds(431, 11, 105, 20);
label2.setForeground(Color.WHITE);
label2.setFont(new Font("Tahoma", Font.BOLD, 14));
panel.add(label2);
setUndecorated(true);
setLayout(null);
setLocation(550, 150);
setSize(700, 500);
setVisible(true);
}
public static void main(String[] args) {
new Department();
}
}