-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form_user.java
353 lines (312 loc) · 17.4 KB
/
Form_user.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import Database.KoneksiDatabase;
import Database.ResultSetTable;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class Form_user extends javax.swing.JInternalFrame {
ResultSet rs;
KoneksiDatabase con;
/**
* Creates new form Form_user
*/
public Form_user() {
con =new KoneksiDatabase(new Database.Parameter().HOST_DB,new Database.Parameter().USERNAME_DB,new Database.Parameter().PASSWORD_DB);
initComponents();
loadTabel();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
tabel_user = new javax.swing.JTable();
btn_create_user = new usu.widget.ButtonGlass();
btn_Edit_user = new usu.widget.ButtonGlass();
btn_Delete_user = new usu.widget.ButtonGlass();
btn_Refresh_user = new usu.widget.ButtonGlass();
panelGlass1 = new usu.widget.glass.PanelGlass();
txt_username_user = new javax.swing.JTextField();
txt_nama_user = new javax.swing.JTextField();
txt_password_user = new javax.swing.JPasswordField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
cb_type = new javax.swing.JComboBox();
jLabel6 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
tabel_user.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"Nama", "Username", "Type"
}
));
tabel_user.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tabel_userMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tabel_user);
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 510, 940, 210));
btn_create_user.setForeground(new java.awt.Color(255, 255, 255));
btn_create_user.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/plus.png"))); // NOI18N
btn_create_user.setText("Create");
btn_create_user.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_create_userActionPerformed(evt);
}
});
getContentPane().add(btn_create_user, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 400, 190, -1));
btn_Edit_user.setForeground(new java.awt.Color(255, 255, 255));
btn_Edit_user.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/pencil_edit.png"))); // NOI18N
btn_Edit_user.setText("Edit");
btn_Edit_user.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_Edit_userActionPerformed(evt);
}
});
getContentPane().add(btn_Edit_user, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 400, 190, -1));
btn_Delete_user.setForeground(new java.awt.Color(255, 255, 255));
btn_Delete_user.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/trash_box.png"))); // NOI18N
btn_Delete_user.setText("Delete");
btn_Delete_user.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_Delete_userActionPerformed(evt);
}
});
getContentPane().add(btn_Delete_user, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 400, 190, -1));
btn_Refresh_user.setForeground(new java.awt.Color(255, 255, 255));
btn_Refresh_user.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/refresh.png"))); // NOI18N
btn_Refresh_user.setText("Refresh");
btn_Refresh_user.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_Refresh_userActionPerformed(evt);
}
});
getContentPane().add(btn_Refresh_user, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 400, 190, -1));
jLabel2.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Nama :");
jLabel3.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Username :");
jLabel4.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("Password :");
jLabel5.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("Type :");
cb_type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Admin", "Staff" }));
cb_type.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cb_typeActionPerformed(evt);
}
});
jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/user_tambah_icon.png"))); // NOI18N
javax.swing.GroupLayout panelGlass1Layout = new javax.swing.GroupLayout(panelGlass1);
panelGlass1.setLayout(panelGlass1Layout);
panelGlass1Layout.setHorizontalGroup(
panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelGlass1Layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelGlass1Layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(cb_type, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(panelGlass1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(txt_password_user))
.addGroup(panelGlass1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(txt_username_user))
.addGroup(panelGlass1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(txt_nama_user, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 189, Short.MAX_VALUE)
.addComponent(jLabel6)
.addContainerGap())
);
panelGlass1Layout.setVerticalGroup(
panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelGlass1Layout.createSequentialGroup()
.addGroup(panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelGlass1Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_nama_user, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_username_user, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(18, 18, 18)
.addGroup(panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_password_user, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelGlass1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cb_type, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)))
.addGroup(panelGlass1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)))
.addContainerGap(54, Short.MAX_VALUE))
);
getContentPane().add(panelGlass1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 940, 260));
jLabel15.setFont(new java.awt.Font("Arial", 1, 48)); // NOI18N
jLabel15.setForeground(new java.awt.Color(255, 255, 255));
jLabel15.setText("Form Tambah User");
getContentPane().add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, -1, -1));
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/backOk.png"))); // NOI18N
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(-50, 20, -1, -1));
pack();
}// </editor-fold>
private void btn_Edit_userActionPerformed(java.awt.event.ActionEvent evt) {
try {
if( !txt_nama_user.getText().isEmpty() && !txt_username_user.getText().isEmpty() && !txt_password_user.getText().isEmpty()){
String kolom[] = {"nama","username","password","type"};
String isi[] = { txt_nama_user.getText(),txt_username_user.getText(),txt_password_user.getText(),cb_type.getSelectedItem().toString()};
con.queryUpdate("user", kolom, isi,"id_user='"+String.valueOf(tabel_user.getValueAt(tabel_user.getSelectedRow(),0))+"'");
JOptionPane.showMessageDialog(this, "Data Berhasil Diedit");
}else{
JOptionPane.showMessageDialog(this, "Data isian ada yang kosong");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error edit data");
}
loadTabel();
clear();
}
private void btn_create_userActionPerformed(java.awt.event.ActionEvent evt) {
create();
}
private void tabel_userMouseClicked(java.awt.event.MouseEvent evt) {
txt_nama_user.setText(String.valueOf(tabel_user.getValueAt(tabel_user.getSelectedRow(),1)));
txt_username_user.setText(String.valueOf( tabel_user.getValueAt(tabel_user.getSelectedRow(),2)));
txt_password_user.setText(String.valueOf( tabel_user.getValueAt(tabel_user.getSelectedRow(),3)));
cb_type.setSelectedItem(String.valueOf(tabel_user.getValueAt(tabel_user.getSelectedRow(),4)));
}
private void btn_Delete_userActionPerformed(java.awt.event.ActionEvent evt) {
try {
String id=String.valueOf(tabel_user.getValueAt(tabel_user.getSelectedRow(),0));
if (JOptionPane.showConfirmDialog(this, "Yakin menghapus data", "Peringatan", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
con.queryDelete("user","id_user="+id);
}else{
return;
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Pilih id terlebih dahulu");
}
loadTabel();
clear();
}
private void btn_Refresh_userActionPerformed(java.awt.event.ActionEvent evt) {
loadTabel();
}
private void cb_typeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Form_user.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Form_user.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Form_user.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Form_user.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Form_user().setVisible(true);
}
});
}
// Variables declaration - do not modify
private usu.widget.ButtonGlass btn_Delete_user;
private usu.widget.ButtonGlass btn_Edit_user;
private usu.widget.ButtonGlass btn_Refresh_user;
private usu.widget.ButtonGlass btn_create_user;
private javax.swing.JComboBox cb_type;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private usu.widget.glass.PanelGlass panelGlass1;
private javax.swing.JTable tabel_user;
private javax.swing.JTextField txt_nama_user;
private javax.swing.JPasswordField txt_password_user;
private javax.swing.JTextField txt_username_user;
// End of variables declaration
private void loadTabel() {
String namaKolom[] = {"id_user","nama","username","type"};
rs=con.querySelect(namaKolom,"user");
tabel_user.setModel(new ResultSetTable(rs));
clear();
}
private void create() {
try {
if( !txt_nama_user.getText().isEmpty() && !txt_username_user.getText().isEmpty() && !txt_password_user.getText().isEmpty()){
String kolom[] = {"nama","username","password","type"};
String isi[] = { txt_nama_user.getText(),txt_username_user.getText(),txt_password_user.getText(),cb_type.getSelectedItem().toString()};
System.out.println( con.queryInsert("user",kolom,isi));
JOptionPane.showMessageDialog(this, "User Berhasil ditambahkan");
}else{
JOptionPane.showMessageDialog(this, "Data User Masih ada yang Kosong");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error input data");
System.out.println("salah");
}
loadTabel();
clear();
}
private void clear() {
txt_nama_user.setText("");
txt_username_user.setText("");
cb_type.setSelectedItem("Admin");
txt_password_user.setText("");
}
}