-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathView_Channel.java
More file actions
161 lines (117 loc) · 5.36 KB
/
View_Channel.java
File metadata and controls
161 lines (117 loc) · 5.36 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
package hospital_management;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class View_Channel extends JFrame {
private JButton precreption = new JButton("Prescription");
private JButton Lab = new JButton("Assign laboratory");
private JButton logout = new JButton("LogOut");
private JButton apoint = new JButton("Appointment");
private JTable table = new JTable();
private JPanel buttonPanel = new JPanel();
private JPanel mainPanel = new JPanel();
View_Channel() {
table1();
// Set BorderLayout for the main panel
mainPanel.setLayout(new BorderLayout());
// Wrap the table in a JScrollPane
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBackground(Color.red);
// Add the scroll pane to the main panel
mainPanel.add(scrollPane, BorderLayout.CENTER);
table.setBackground(Color.cyan);
// Add the buttons to the button panel
buttonPanel.add(precreption);
buttonPanel.add(apoint);
buttonPanel.add(logout);
buttonPanel.add(Lab);
precreption.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedIndex=table.getSelectedRow();
if (selectedIndex != -1) {
DefaultTableModel d1=(DefaultTableModel)table.getModel();
String chno=d1.getValueAt(selectedIndex, 0).toString();
String docName=d1.getValueAt(selectedIndex, 1).toString();
new Prescription(chno,docName);
}else{JOptionPane.showMessageDialog(null, "please select th row!!!");}
setVisible(false);
}
});
Lab.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedIndex=table.getSelectedRow();
if (selectedIndex != -1) {
DefaultTableModel d1=(DefaultTableModel)table.getModel();
String chno=d1.getValueAt(selectedIndex, 0).toString();
String docName=d1.getValueAt(selectedIndex, 1).toString();
new Lboratoriest(chno,docName);
}else{JOptionPane.showMessageDialog(null, "please select th row!!!");}
setVisible(false);
}
});
logout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Doctor();
setVisible(false);
}
});
apoint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selectedIndex=table.getSelectedRow();
if (selectedIndex != -1) {
DefaultTableModel d1=(DefaultTableModel)table.getModel();
String chno=d1.getValueAt(selectedIndex, 0).toString();
String docName=d1.getValueAt(selectedIndex, 1).toString();
String paName=d1.getValueAt(selectedIndex, 2).toString();
new Appointment(chno,docName,paName);
}else{JOptionPane.showMessageDialog(null, "please select th row!!!");}
setVisible(false);
}
});
// Add the button panel to the main panel
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
// Add the main panel to the JFrame
add(mainPanel);
setTitle("View Channel");
setSize(500, 300);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void table1() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
PreparedStatement pst = con.prepareStatement("SELECT * FROM channel");
ResultSet rs = pst.executeQuery();
DefaultTableModel model = new DefaultTableModel();
model.addColumn("channelNo");
model.addColumn("doctor_name");
model.addColumn("patientName");
model.addColumn("roomNo");
model.addColumn("channelDate ");
while (rs.next()) {
Object[] rowData = new Object[5];
rowData[0] = rs.getString("channelNo");
rowData[1] = rs.getString("doctor_name");
rowData[2] = rs.getString("patientName");
rowData[3] = rs.getString("roomNo");
rowData[4] = rs.getString("channelDate");
model.addRow(rowData);
}
table.setModel(model);
rs.close();
pst.close();
con.close();
} catch (ClassNotFoundException | SQLException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new View_Channel();
});
}
}