· 8 years ago · Jan 04, 2018, 08:22 AM
1public class Orang {
2
3 private String name;
4 private String city;
5 private String phone;
6
7 public Orang(int id){
8 this.name = name;
9 this.city = city;
10 this.phone = phone;
11 }
12
13 // untuk mendaptkan inputan nama
14 public String getName(){
15 return this.name;
16 }
17 public String getCity(){
18 return this.city;
19 }
20 public String getphone(){
21 return this.phone;
22 }
23 //atur inputan nama
24 public void setName(String name){
25 this.name= name;
26 }
27 public void setCity(String city){
28 this.city= city;
29 }
30 public void setPhone(String phone){
31 this.phone= phone;
32 }
33 public static void main(String[] args) {
34 // TODO code application logic here
35 }
36}
37
38
39
40package phonebook2;
41
42public class Person {
43
44 private String name;
45 private String city;
46 private String phone;
47
48 public Person(int id){
49 this("name" + id, "city" + id, "phone" + id);
50 }
51
52 public Person(String name , String city, String phone ){
53 this.name = name;
54 this.city = city;
55 this.phone = phone;
56 }
57
58 // get method
59 public String getName(){
60 return this.name;
61 }
62 public String getCity(){
63 return this.city;
64 }
65 public String getPhone(){
66 return this.phone;
67 }
68
69 // set method
70 public void setName(String name){
71 this.name= name;
72 }
73 public void setCity(String city){
74 this.city = city;
75 }
76 public void setPhone(String phone){
77 this.phone = phone;
78 }
79}
80
81package phonebook2;
82
83import java.awt.Color;
84import java.awt.Component;
85import java.awt.Dimension;
86import java.awt.Toolkit;
87import java.awt.event.KeyEvent;
88import java.awt.print.PrinterException;
89import java.io.BufferedWriter;
90import java.io.FileWriter;
91import java.sql.Connection;
92import java.sql.DriverManager;
93import java.sql.PreparedStatement;
94import java.sql.ResultSet;
95import java.sql.Statement;
96import java.text.MessageFormat;
97import java.util.Vector;
98import javax.swing.JCheckBox;
99import javax.swing.JOptionPane;
100import javax.swing.JSlider;
101import javax.swing.JTable;
102import javax.swing.JTextField;
103import javax.swing.UIManager;
104import javax.swing.table.AbstractTableModel;
105import javax.swing.table.DefaultTableCellRenderer;
106import javax.swing.table.TableColumn;
107
108public class Form extends javax.swing.JFrame {
109
110 private Connection con = null;
111 private PersonModel model = null;
112
113 private String database = "notebook";
114 private String tableName = database + ".table2";
115 private String mysql_password = "";
116
117 public Form() {
118 initComponents();
119
120 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
121 int x = d.width/2 - this.getWidth()/2,
122 y = d.height/2 - this.getHeight()/2;
123 setLocation(x, y);
124
125 scrollPane.getViewport().setBackground(Color.WHITE);
126 }
127
128 @SuppressWarnings("unchecked")
129
130 // <editor-fold defaultstate="collapsed" desc="Generated Code">
131 private void initComponents() {
132
133 mainPanel = new javax.swing.JPanel();
134 settingPanel = new javax.swing.JPanel();
135 cb_horizLine = new javax.swing.JCheckBox();
136 cb_verticLine = new javax.swing.JCheckBox();
137 slider = new javax.swing.JSlider();
138 cb_selRow = new javax.swing.JCheckBox();
139 cb_selCol = new javax.swing.JCheckBox();
140 cb_shwDlg = new javax.swing.JCheckBox();
141 infoPanel = new javax.swing.JPanel();
142 label1 = new javax.swing.JLabel();
143 Name = new javax.swing.JTextField();
144 City = new javax.swing.JTextField();
145 Phone = new javax.swing.JTextField();
146 label2 = new javax.swing.JLabel();
147 label3 = new javax.swing.JLabel();
148 Insert = new javax.swing.JButton();
149 Reset = new javax.swing.JButton();
150 searchPanel = new javax.swing.JPanel();
151 label4 = new javax.swing.JLabel();
152 fieldName = new javax.swing.JComboBox();
153 value = new javax.swing.JTextField();
154 tablePanel = new javax.swing.JPanel();
155 scrollPane = new javax.swing.JScrollPane();
156 dataTable = new javax.swing.JTable();
157 Backup = new javax.swing.JButton();
158 DeleteAll = new javax.swing.JButton();
159 Print = new javax.swing.JButton();
160
161 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
162 setTitle("phonebook2");
163 setResizable(false);
164 addWindowListener(new java.awt.event.WindowAdapter() {
165 public void windowOpened(java.awt.event.WindowEvent evt) {
166 formWindowOpened(evt);
167 }
168 });
169
170 mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12))); // NOI18N
171
172 settingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Setting", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
173
174 cb_horizLine.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
175 cb_horizLine.setSelected(true);
176 cb_horizLine.setText("show horiz-line");
177 cb_horizLine.setNextFocusableComponent(cb_verticLine);
178 cb_horizLine.addActionListener(new java.awt.event.ActionListener() {
179 public void actionPerformed(java.awt.event.ActionEvent evt) {
180 cb_horizLineActionPerformed(evt);
181 }
182 });
183
184 cb_verticLine.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
185 cb_verticLine.setSelected(true);
186 cb_verticLine.setText("show vertic-line");
187 cb_verticLine.setNextFocusableComponent(cb_selRow);
188 cb_verticLine.addActionListener(new java.awt.event.ActionListener() {
189 public void actionPerformed(java.awt.event.ActionEvent evt) {
190 cb_verticLineActionPerformed(evt);
191 }
192 });
193
194 slider.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
195 slider.setOrientation(javax.swing.JSlider.VERTICAL);
196 slider.setValue(20);
197 slider.setNextFocusableComponent(Name);
198 slider.addChangeListener(new javax.swing.event.ChangeListener() {
199 public void stateChanged(javax.swing.event.ChangeEvent evt) {
200 sliderStateChanged(evt);
201 }
202 });
203
204 cb_selRow.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
205 cb_selRow.setSelected(true);
206 cb_selRow.setText("select row");
207 cb_selRow.setNextFocusableComponent(cb_selCol);
208 cb_selRow.addActionListener(new java.awt.event.ActionListener() {
209 public void actionPerformed(java.awt.event.ActionEvent evt) {
210 cb_selRowActionPerformed(evt);
211 }
212 });
213
214 cb_selCol.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
215 cb_selCol.setText("select column");
216 cb_selCol.setNextFocusableComponent(slider);
217 cb_selCol.addActionListener(new java.awt.event.ActionListener() {
218 public void actionPerformed(java.awt.event.ActionEvent evt) {
219 cb_selColActionPerformed(evt);
220 }
221 });
222
223 cb_shwDlg.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
224 cb_shwDlg.setSelected(true);
225 cb_shwDlg.setText("show deleting dialog");
226 cb_shwDlg.setNextFocusableComponent(slider);
227
228 javax.swing.GroupLayout settingPanelLayout = new javax.swing.GroupLayout(settingPanel);
229 settingPanel.setLayout(settingPanelLayout);
230 settingPanelLayout.setHorizontalGroup(
231 settingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232 .addGroup(settingPanelLayout.createSequentialGroup()
233 .addContainerGap()
234 .addGroup(settingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
235 .addComponent(cb_verticLine, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
236 .addComponent(cb_horizLine, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
237 .addComponent(cb_selRow, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
238 .addComponent(cb_selCol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
239 .addComponent(cb_shwDlg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
240 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
241 .addComponent(slider, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addContainerGap())
243 );
244 settingPanelLayout.setVerticalGroup(
245 settingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246 .addGroup(settingPanelLayout.createSequentialGroup()
247 .addContainerGap()
248 .addGroup(settingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
249 .addComponent(slider, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
250 .addGroup(settingPanelLayout.createSequentialGroup()
251 .addComponent(cb_horizLine, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
252 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
253 .addComponent(cb_verticLine, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
254 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
255 .addComponent(cb_selRow, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
256 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
257 .addComponent(cb_selCol, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
258 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
259 .addComponent(cb_shwDlg, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
260 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
261 );
262
263 infoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "insert", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
264
265 label1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
266 label1.setText("name :");
267
268 Name.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
269
270 City.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
271
272 Phone.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
273
274 label2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
275 label2.setText("phone :");
276
277 label3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
278 label3.setText("city :");
279
280 Insert.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
281 Insert.setText("insert");
282 Insert.addActionListener(new java.awt.event.ActionListener() {
283 public void actionPerformed(java.awt.event.ActionEvent evt) {
284 InsertActionPerformed(evt);
285 }
286 });
287
288 Reset.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
289 Reset.setText("reset");
290 Reset.setNextFocusableComponent(fieldName);
291 Reset.addActionListener(new java.awt.event.ActionListener() {
292 public void actionPerformed(java.awt.event.ActionEvent evt) {
293 ResetActionPerformed(evt);
294 }
295 });
296
297 javax.swing.GroupLayout infoPanelLayout = new javax.swing.GroupLayout(infoPanel);
298 infoPanel.setLayout(infoPanelLayout);
299 infoPanelLayout.setHorizontalGroup(
300 infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301 .addGroup(infoPanelLayout.createSequentialGroup()
302 .addContainerGap()
303 .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
304 .addGroup(infoPanelLayout.createSequentialGroup()
305 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
306 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307 .addComponent(Name))
308 .addGroup(infoPanelLayout.createSequentialGroup()
309 .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
310 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
311 .addComponent(City))
312 .addGroup(infoPanelLayout.createSequentialGroup()
313 .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
314 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315 .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
316 .addGroup(infoPanelLayout.createSequentialGroup()
317 .addComponent(Insert, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
318 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
319 .addComponent(Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
320 .addComponent(Phone))))
321 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
322 );
323 infoPanelLayout.setVerticalGroup(
324 infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
325 .addGroup(infoPanelLayout.createSequentialGroup()
326 .addContainerGap()
327 .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
328 .addComponent(label1)
329 .addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
330 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
331 .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
332 .addComponent(label3)
333 .addComponent(City, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
334 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
335 .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
336 .addComponent(label2)
337 .addComponent(Phone, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
338 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339 .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
340 .addComponent(Reset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
341 .addComponent(Insert, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
342 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
343 );
344
345 searchPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
346
347 label4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
348 label4.setText("field :");
349
350 fieldName.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
351 fieldName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "name", "city", "phone" }));
352 fieldName.setNextFocusableComponent(value);
353
354 value.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
355 value.setNextFocusableComponent(cb_horizLine);
356 value.addKeyListener(new java.awt.event.KeyAdapter() {
357 public void keyReleased(java.awt.event.KeyEvent evt) {
358 valueKeyReleased(evt);
359 }
360 });
361
362 javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
363 searchPanel.setLayout(searchPanelLayout);
364 searchPanelLayout.setHorizontalGroup(
365 searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
366 .addGroup(searchPanelLayout.createSequentialGroup()
367 .addContainerGap()
368 .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
369 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
370 .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
371 .addComponent(value)
372 .addComponent(fieldName, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
373 .addContainerGap())
374 );
375 searchPanelLayout.setVerticalGroup(
376 searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
377 .addGroup(searchPanelLayout.createSequentialGroup()
378 .addContainerGap()
379 .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
380 .addComponent(label4)
381 .addComponent(fieldName, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
382 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
383 .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
384 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
385 );
386
387 tablePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Display", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
388
389 dataTable.setModel(new javax.swing.table.DefaultTableModel(
390 new Object [][] {
391
392 },
393 new String [] {
394
395 }
396 ));
397 dataTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
398 dataTable.setGridColor(new java.awt.Color(204, 204, 204));
399 dataTable.setRowHeight(20);
400 dataTable.setSelectionBackground(new java.awt.Color(102, 182, 250));
401 dataTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
402 dataTable.getTableHeader().setReorderingAllowed(false);
403 dataTable.addKeyListener(new java.awt.event.KeyAdapter() {
404 public void keyReleased(java.awt.event.KeyEvent evt) {
405 dataTableKeyReleased(evt);
406 }
407 });
408 scrollPane.setViewportView(dataTable);
409
410 Backup.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
411 Backup.setText("backup");
412 Backup.addActionListener(new java.awt.event.ActionListener() {
413 public void actionPerformed(java.awt.event.ActionEvent evt) {
414 BackupActionPerformed(evt);
415 }
416 });
417
418 DeleteAll.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
419 DeleteAll.setText("delete all");
420 DeleteAll.addActionListener(new java.awt.event.ActionListener() {
421 public void actionPerformed(java.awt.event.ActionEvent evt) {
422 DeleteAllActionPerformed(evt);
423 }
424 });
425
426 Print.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
427 Print.setText("print");
428 Print.addActionListener(new java.awt.event.ActionListener() {
429 public void actionPerformed(java.awt.event.ActionEvent evt) {
430 PrintActionPerformed(evt);
431 }
432 });
433
434 javax.swing.GroupLayout tablePanelLayout = new javax.swing.GroupLayout(tablePanel);
435 tablePanel.setLayout(tablePanelLayout);
436 tablePanelLayout.setHorizontalGroup(
437 tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
438 .addGroup(tablePanelLayout.createSequentialGroup()
439 .addContainerGap()
440 .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
441 .addComponent(scrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
442 .addGroup(tablePanelLayout.createSequentialGroup()
443 .addComponent(Backup, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
444 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
445 .addComponent(DeleteAll, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
446 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
447 .addComponent(Print, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
448 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
449 );
450 tablePanelLayout.setVerticalGroup(
451 tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
452 .addGroup(tablePanelLayout.createSequentialGroup()
453 .addComponent(scrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
454 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
455 .addGroup(tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
456 .addComponent(Backup, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
457 .addComponent(DeleteAll, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
458 .addComponent(Print, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
459 );
460
461 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
462 mainPanel.setLayout(mainPanelLayout);
463 mainPanelLayout.setHorizontalGroup(
464 mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
465 .addGroup(mainPanelLayout.createSequentialGroup()
466 .addContainerGap()
467 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
468 .addComponent(infoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
469 .addComponent(searchPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
470 .addComponent(settingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
471 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
472 .addComponent(tablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
473 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
474 );
475 mainPanelLayout.setVerticalGroup(
476 mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
477 .addGroup(mainPanelLayout.createSequentialGroup()
478 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
479 .addGroup(mainPanelLayout.createSequentialGroup()
480 .addComponent(infoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
481 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
482 .addComponent(searchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
483 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
484 .addComponent(settingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
485 .addComponent(tablePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
486 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
487 );
488
489 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
490 getContentPane().setLayout(layout);
491 layout.setHorizontalGroup(
492 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
493 .addGroup(layout.createSequentialGroup()
494 .addContainerGap()
495 .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
496 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
497 );
498 layout.setVerticalGroup(
499 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
500 .addGroup(layout.createSequentialGroup()
501 .addContainerGap()
502 .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
503 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
504 );
505
506 pack();
507 }// </editor-fold>
508
509 private void ResetActionPerformed(java.awt.event.ActionEvent evt) {
510 for(Component comp : this.infoPanel.getComponents())
511 if(comp instanceof JTextField)
512 ((JTextField)comp).setText("");
513 }
514
515 private void formWindowOpened(java.awt.event.WindowEvent evt) {
516 try{
517 // found jdbc driver for mysql
518 Class.forName("com.mysql.jdbc.Driver");
519 // create connection to mysql
520 String url = "jdbc:mysql://localhost/",
521 uname = "root",
522 upass = mysql_password;
523
524 con = DriverManager.getConnection(url, uname, upass);
525
526 createDatabase();
527 createTable();
528 Vector data = getData("");
529 showData(data);
530 //set database
531 con.setCatalog(database);
532
533 }catch(Exception e){
534 JOptionPane.showMessageDialog(this, e.getMessage() + "\nCan not connected to mysql!");
535 this.dispose();
536 }
537 }
538
539 private void InsertActionPerformed(java.awt.event.ActionEvent evt) {
540 try{
541 if(isEmpty())
542 throw new Exception("please enter all data!");
543
544 // if phone is frequency dont insert
545 if(isExitsPhone())
546 throw new Exception("phone number is frequency!");
547
548 boolean ok = insert();
549 if(ok){
550 Vector data = getData("");
551 showData(data);
552 } else
553 throw new Exception("an error occure at inserting!");
554
555 }catch(Exception e){
556 JOptionPane.showMessageDialog(this, e.getMessage());
557 }
558 }
559
560 private void dataTableKeyReleased(java.awt.event.KeyEvent evt) {
561 if(evt.getKeyCode() != KeyEvent.VK_DELETE)
562 return;
563
564 JTable table = (JTable)evt.getSource();
565
566 int row = table.getSelectedRow();
567 if(row < 0)
568 return;
569 Object phone = table.getValueAt(row, 2);
570
571 if(cb_shwDlg.isSelected()){
572 int option = JOptionPane.showConfirmDialog(this, "Do you want to delete this item?",
573 "delete", JOptionPane.YES_NO_CANCEL_OPTION);
574 if(option != JOptionPane.YES_OPTION)
575 return;
576 }
577
578 try{
579 boolean ok = delete(phone);
580 if(ok){
581 Vector data = getData("");
582 showData(data);
583 } else
584 throw new Exception("an error occure at deleting!");
585
586 }catch(Exception e){
587 JOptionPane.showMessageDialog(this, e.getMessage());
588 }
589 }
590
591 private void valueKeyReleased(java.awt.event.KeyEvent evt) {
592 String text = value.getText().trim();
593 try{
594 String where = "";
595 if(!text.equals(""))
596 where = " WHERE " + fieldName.getSelectedItem() + " LIKE '" + text + "%'";
597 Vector data = getData(where);
598 showData(data);
599 }catch(Exception e){
600 }
601 }
602
603 private void cb_horizLineActionPerformed(java.awt.event.ActionEvent evt) {
604 boolean show = ((JCheckBox)evt.getSource()).isSelected();
605 dataTable.setShowHorizontalLines(show);
606 }
607
608 private void cb_verticLineActionPerformed(java.awt.event.ActionEvent evt) {
609 boolean show = ((JCheckBox)evt.getSource()).isSelected();
610 dataTable.setShowVerticalLines(show);
611 }
612
613 private void cb_selRowActionPerformed(java.awt.event.ActionEvent evt) {
614 boolean show = ((JCheckBox)evt.getSource()).isSelected();
615 dataTable.setRowSelectionAllowed(show);
616 }
617
618 private void cb_selColActionPerformed(java.awt.event.ActionEvent evt) {
619 boolean show = ((JCheckBox)evt.getSource()).isSelected();
620 dataTable.setColumnSelectionAllowed(show);
621 }
622
623 private void sliderStateChanged(javax.swing.event.ChangeEvent evt) {
624 int height = ((JSlider)evt.getSource()).getValue() + 1;
625 dataTable.setRowHeight(height);
626 }
627
628 private void PrintActionPerformed(java.awt.event.ActionEvent evt) {
629 MessageFormat headerFmt = new MessageFormat("Notebook"),
630 footerFmt = new MessageFormat("Page {0}");
631
632 JTable.PrintMode printMode = JTable.PrintMode.FIT_WIDTH;
633
634 try {
635 boolean status = dataTable.print(printMode, headerFmt, footerFmt);
636
637 if (status) {
638 JOptionPane.showMessageDialog(dataTable.getParent(), "printing is Complete",
639 "printing Result", JOptionPane.INFORMATION_MESSAGE);
640 } else {
641 JOptionPane.showMessageDialog(dataTable.getParent(), "printing Cancelled",
642 "printing Result",JOptionPane.INFORMATION_MESSAGE);
643 }
644 } catch (PrinterException pe) {
645 String errorMessage = MessageFormat.format("printing Failed", new Object[] {pe.getMessage()});
646 JOptionPane.showMessageDialog(dataTable.getParent(), errorMessage,
647 "printing Result", JOptionPane.ERROR_MESSAGE);
648 } catch (SecurityException se) {
649 String errorMessage = MessageFormat.format("printing Failed", new Object[] {se.getMessage()});
650 JOptionPane.showMessageDialog(dataTable.getParent(), errorMessage,
651 "TableDemo.printingResult", JOptionPane.ERROR_MESSAGE);
652 }
653}
654
655 private void DeleteAllActionPerformed(java.awt.event.ActionEvent evt) {
656 try{
657 int row = deleteall();
658 Vector data = getData("");
659 showData(data);
660 throw new Exception(row + " row(s) deleted!");
661 }catch(Exception e){
662 JOptionPane.showMessageDialog(this, e.getMessage());
663 }
664}
665
666 private void BackupActionPerformed(java.awt.event.ActionEvent evt) {
667 try{
668 BufferedWriter writer = new BufferedWriter(new FileWriter("backup.sql"));
669 Vector allData = getData("");
670
671 for(int row = 0; row < allData.size(); ++row){
672 Person data = (Person)allData.elementAt(row);
673
674 String sql = "insert into " + tableName + " values ('" + data.getName() + "' , '" +
675 data.getCity() + "' , '" + data.getPhone() + "');";
676 writer.write(sql);
677 writer.newLine();
678 }
679 writer.close();
680 JOptionPane.showMessageDialog(this, "successfull backupping!" , "backup", JOptionPane.INFORMATION_MESSAGE);
681 }catch(Exception e){
682 JOptionPane.showMessageDialog(this, "an error occure at backupping!" , "formWindowOpened", JOptionPane.ERROR_MESSAGE);
683 }
684}
685 private boolean isEmpty(){
686 Component[] comps = infoPanel.getComponents();
687 for(int i = 0; i < comps.length; ++i){
688 Component comp = comps[i];
689 if(comp instanceof JTextField){
690 JTextField field = (JTextField)comp;
691 if(field.getText().equals(""))
692 return true;
693 }
694 }
695 return false;
696 }
697
698 private void createDatabase() throws Exception{
699 Statement stm = this.con.createStatement();
700 stm.execute("CREATE DATABASE IF NOT EXISTS " + database +
701 " DEFAULT CHARACTER SET utf8 COLLATE utf8_persian_ci");
702 }
703
704 private void createTable() throws Exception{
705 Statement stm = this.con.createStatement();
706
707 String query = "CREATE TABLE IF NOT EXISTS " + tableName +
708 "(name VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL ," +
709 " city VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL ," +
710 " phone VARCHAR( 15 ) NOT NULL, " +
711 "PRIMARY KEY (phone) )";
712 stm.execute(query);
713 }
714
715 private boolean insert()throws Exception{
716 String query = "INSERT INTO " + tableName + " VALUES(?, ?, ?)";
717 PreparedStatement pstm = this.con.prepareStatement(query);
718
719 pstm.setObject(1, Name.getText().trim());
720 pstm.setObject(2, City.getText().trim());
721 pstm.setObject(3, Phone.getText().trim());
722
723 int result = pstm.executeUpdate();
724
725 return (result > 0);
726 }
727
728 private boolean update(Object[] data)throws Exception{
729 String query = "UPDATE " + tableName + " SET name=?, city=? WHERE phone=?";
730 PreparedStatement pstm = con.prepareStatement(query);
731
732 pstm.setObject(1, data[0]);
733 pstm.setObject(2, data[1]);
734 pstm.setObject(3, data[2]);
735
736 int result = pstm.executeUpdate();
737
738 return (result > 0);
739 }
740
741 private boolean isExitsPhone() throws Exception{
742 String query = "SELECT COUNT(*) FROM " + tableName + " WHERE phone=?";
743 PreparedStatement pstm = this.con.prepareStatement(query);
744 pstm.setObject(1, Phone.getText());
745
746 ResultSet result = pstm.executeQuery();
747
748 result.next();
749 return (result.getInt(1) > 0);
750 }
751
752 private boolean delete(Object data)throws Exception{
753 String query = "DELETE FROM " + tableName + " WHERE phone=?";
754 PreparedStatement pstm = this.con.prepareStatement(query);
755 pstm.setObject(1, data);
756
757 int result = pstm.executeUpdate();
758 return (result > 0);
759 }
760
761 private int deleteall()throws Exception{
762 Statement stm = con.createStatement();
763 int result = stm.executeUpdate("DELETE FROM " + tableName );
764 return result;
765 }
766
767 private Vector getData(String where) throws Exception{
768 Vector info = new Vector();
769
770 Statement stm = con.createStatement();
771 ResultSet result = stm.executeQuery("SELECT * FROM " + tableName + where);
772
773 while(result.next()){
774 String name = result.getObject("name").toString(),
775 city = result.getObject("city").toString(),
776 phone = result.getObject("phone").toString();
777
778 info.addElement(new Person(name, city, phone));
779 }
780 return info;
781 }
782
783 private void showData(Vector data) throws Exception{
784 model = new PersonModel(data);
785 dataTable.setModel(model);
786
787 int[] width = {
788 80, 80, 120
789 };
790 int count = dataTable.getColumnModel().getColumnCount();
791 for(int i = 0; i < count; ++i){
792 dataTable.getColumnModel().getColumn(i).setMinWidth(width[i]);
793 dataTable.getColumnModel().getColumn(i).setMaxWidth(width[i] + 20);
794 }
795 // set phone column background
796 TableColumn phoneColumn = dataTable.getColumnModel().getColumn(2);
797 DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
798 renderer.setBackground(new Color(245, 245, 245));
799 phoneColumn.setCellRenderer(renderer);
800 }
801
802 public static void main(String args[]) {
803 try{
804 for(UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()){
805 //Metal , Nimbus, CDE/Motif, Windows, Windows Classic
806 if(laf.getName().equals("Nimbus"))
807 UIManager.setLookAndFeel(laf.getClassName());
808 //System.out.println(laf.getName());
809 }
810 }catch(Exception e){
811 }
812 java.awt.EventQueue.invokeLater(new Runnable() {
813 @Override
814 public void run() {
815 new Form().setVisible(true);
816 }
817 });
818 }
819
820 private class PersonModel extends AbstractTableModel{
821
822 private Vector<Person> items;
823 private String[] columns = {
824 "Name","City","Phone"
825 };
826 public static final int NAME = 0;
827 public static final int CITY = 1;
828 public static final int PHONE = 2;
829
830 public PersonModel(Vector items) {
831 this.items = items;
832 }
833
834 @Override public int getRowCount() {
835 return (items == null ? 0 : items.size());
836 }
837 @Override public int getColumnCount() {
838 return columns.length;
839 }
840 @Override public String getColumnName(int columnIndex) {
841 return columns[columnIndex];
842 }
843 @Override public boolean isCellEditable(int rowIndex, int columnIndex) {
844 return (columnIndex != PHONE);
845 }
846 @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
847 if(aValue.toString().equals(""))
848 return;
849 Person row = items.elementAt(rowIndex);
850 switch(columnIndex){
851 case NAME :
852 row.setName((String)aValue);
853 break;
854 case CITY :
855 row.setCity((String)aValue);
856 break;
857 case PHONE :
858 row.setPhone((String)aValue);
859 break;
860 }
861 // update database
862 try{
863 boolean edit = update(new Object[] {
864 getValueAt(rowIndex, NAME),
865 getValueAt(rowIndex, CITY),
866 getValueAt(rowIndex, PHONE)
867 });
868 if(!edit)
869 throw new Exception("an error occure at updating!");
870 }catch(Exception e){
871 JOptionPane.showMessageDialog(Form.this, e.getMessage());
872 }
873 }
874
875 @Override public Object getValueAt(int rowIndex, int columnIndex) {
876 Person info = items.elementAt(rowIndex);
877 switch(columnIndex){
878 case NAME : return info.getName();
879 case CITY : return info.getCity();
880 case PHONE : return info.getPhone();
881 }
882 return "NULL";
883 }
884 }
885
886 // Variables declaration - do not modify
887 private javax.swing.JButton Backup;
888 private javax.swing.JTextField City;
889 private javax.swing.JButton DeleteAll;
890 private javax.swing.JButton Insert;
891 private javax.swing.JTextField Name;
892 private javax.swing.JTextField Phone;
893 private javax.swing.JButton Print;
894 private javax.swing.JButton Reset;
895 private javax.swing.JCheckBox cb_horizLine;
896 private javax.swing.JCheckBox cb_selCol;
897 private javax.swing.JCheckBox cb_selRow;
898 private javax.swing.JCheckBox cb_shwDlg;
899 private javax.swing.JCheckBox cb_verticLine;
900 private javax.swing.JTable dataTable;
901 private javax.swing.JComboBox fieldName;
902 private javax.swing.JPanel infoPanel;
903 private javax.swing.JLabel label1;
904 private javax.swing.JLabel label2;
905 private javax.swing.JLabel label3;
906 private javax.swing.JLabel label4;
907 private javax.swing.JPanel mainPanel;
908 private javax.swing.JScrollPane scrollPane;
909 private javax.swing.JPanel searchPanel;
910 private javax.swing.JPanel settingPanel;
911 private javax.swing.JSlider slider;
912 private javax.swing.JPanel tablePanel;
913 private javax.swing.JTextField value;
914 // End of variables declaration
915
916}
917
918
919/*
920 * To change this template, choose Tools | Templates
921 * and open the template in the editor.
922 */
923package orang;
924
925import java.awt.*;
926import java.awt.event.KeyEvent;
927import java.awt.print.PrinterException;
928import java.io.BufferedWriter;
929import java.io.FileWriter;
930import java.sql.Connection;
931import java.sql.DriverManager;
932import java.sql.PreparedStatement;
933import java.sql.ResultSet;
934import java.sql.Statement;
935import java.text.MessageFormat;
936import java.util.Vector;
937import javax.swing.JCheckBox;
938import javax.swing.JOptionPane;
939import javax.swing.JSlider;
940import javax.swing.JTable;
941import javax.swing.JTextField;
942import javax.swing.UIManager;
943import javax.swing.table.AbstractTableModel;
944import javax.swing.table.DefaultTableCellRenderer;
945import javax.swing.table.TableColumn;
946public class form_ extends javax.swing.JFrame {
947
948 private Connection con = null;
949 private Orang model = null;
950
951 private String database = "notebook";
952 private String tableName =database + ".table2";
953 private String mysql_password = "123456";
954
955
956 public form_() {
957 initComponents();
958
959 Dimension d =Toolkit.getDefaultToolkit().getScreenSize();
960 int x = d.width/2 - this.getWidth()/2,
961 y = d.height/2 - this.getHeight()/2;
962 setLocation(x,y);
963
964
965 }
966
967 /**
968 * This method is called from within the constructor to initialize the form.
969 * WARNING: Do NOT modify this code. The content of this method is always
970 * regenerated by the Form Editor.
971 */
972 @SuppressWarnings("unchecked")
973 // <editor-fold defaultstate="collapsed" desc="Generated Code">
974 private void initComponents() {
975
976 jTextField1 = new javax.swing.JTextField();
977 jLabel5 = new javax.swing.JLabel();
978 jScrollPane1 = new javax.swing.JScrollPane();
979 jTable1 = new javax.swing.JTable();
980 jLabel1 = new javax.swing.JLabel();
981 jLabel2 = new javax.swing.JLabel();
982 jLabel3 = new javax.swing.JLabel();
983 jLabel4 = new javax.swing.JLabel();
984 jTextField2 = new javax.swing.JTextField();
985 jTextField3 = new javax.swing.JTextField();
986 jTextField4 = new javax.swing.JTextField();
987 jTextField5 = new javax.swing.JTextField();
988 jButton1 = new javax.swing.JButton();
989 jButton2 = new javax.swing.JButton();
990 jLabel6 = new javax.swing.JLabel();
991 jLabel7 = new javax.swing.JLabel();
992 jComboBox1 = new javax.swing.JComboBox();
993 jLabel8 = new javax.swing.JLabel();
994 jCheckBox1 = new javax.swing.JCheckBox();
995 jCheckBox2 = new javax.swing.JCheckBox();
996 jCheckBox3 = new javax.swing.JCheckBox();
997 jCheckBox4 = new javax.swing.JCheckBox();
998 jCheckBox5 = new javax.swing.JCheckBox();
999 jLabel9 = new javax.swing.JLabel();
1000 jButton3 = new javax.swing.JButton();
1001 jButton4 = new javax.swing.JButton();
1002 jButton5 = new javax.swing.JButton();
1003 jScrollPane2 = new javax.swing.JScrollPane();
1004 jTable2 = new javax.swing.JTable();
1005 jToolBar1 = new javax.swing.JToolBar();
1006
1007 jTextField1.setText("jTextField1");
1008
1009 jLabel5.setText("jLabel5");
1010
1011 jTable1.setModel(new javax.swing.table.DefaultTableModel(
1012 new Object [][] {
1013 {null, null, null, null},
1014 {null, null, null, null},
1015 {null, null, null, null},
1016 {null, null, null, null}
1017 },
1018 new String [] {
1019 "Title 1", "Title 2", "Title 3", "Title 4"
1020 }
1021 ));
1022 jScrollPane1.setViewportView(jTable1);
1023
1024 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
1025
1026 jLabel1.setText("Isert");
1027
1028 jLabel2.setText("name");
1029
1030 jLabel3.setText("city");
1031
1032 jLabel4.setText("phone");
1033
1034 jTextField2.addActionListener(new java.awt.event.ActionListener() {
1035 public void actionPerformed(java.awt.event.ActionEvent evt) {
1036 jTextField2ActionPerformed(evt);
1037 }
1038 });
1039
1040 jTextField3.addActionListener(new java.awt.event.ActionListener() {
1041 public void actionPerformed(java.awt.event.ActionEvent evt) {
1042 jTextField3ActionPerformed(evt);
1043 }
1044 });
1045
1046 jButton1.setText("insert");
1047
1048 jButton2.setText("reset");
1049
1050 jLabel6.setText("field:");
1051
1052 jLabel7.setText("search");
1053
1054 jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "name", "city", "phone" }));
1055 jComboBox1.addActionListener(new java.awt.event.ActionListener() {
1056 public void actionPerformed(java.awt.event.ActionEvent evt) {
1057 jComboBox1ActionPerformed(evt);
1058 }
1059 });
1060
1061 jLabel8.setText(" seting");
1062
1063 jCheckBox1.setText("showhoriz-line");
1064
1065 jCheckBox2.setText("show vertic-line");
1066
1067 jCheckBox3.setText("select row");
1068 jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
1069 public void actionPerformed(java.awt.event.ActionEvent evt) {
1070 jCheckBox3ActionPerformed(evt);
1071 }
1072 });
1073
1074 jCheckBox4.setText("select kolom");
1075
1076 jCheckBox5.setText("jCheckBox5");
1077 jCheckBox5.setActionCommand("show deleting dialog");
1078
1079 jLabel9.setText("display");
1080
1081 jButton3.setText("Backup");
1082 jButton3.addActionListener(new java.awt.event.ActionListener() {
1083 public void actionPerformed(java.awt.event.ActionEvent evt) {
1084 jButton3ActionPerformed(evt);
1085 }
1086 });
1087
1088 jButton4.setText("Dellete all");
1089 jButton4.addActionListener(new java.awt.event.ActionListener() {
1090 public void actionPerformed(java.awt.event.ActionEvent evt) {
1091 jButton4ActionPerformed(evt);
1092 }
1093 });
1094
1095 jButton5.setText("Print");
1096
1097 jTable2.setModel(new javax.swing.table.DefaultTableModel(
1098 new Object [][] {
1099 {null, null, null, null},
1100 {null, null, null, null},
1101 {null, null, null, null},
1102 {null, null, null, null}
1103 },
1104 new String [] {
1105 "Title 1", "Title 2", "Title 3", "Title 4"
1106 }
1107 ));
1108 jScrollPane2.setViewportView(jTable2);
1109
1110 jToolBar1.setRollover(true);
1111
1112 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
1113 getContentPane().setLayout(layout);
1114 layout.setHorizontalGroup(
1115 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1116 .addGroup(layout.createSequentialGroup()
1117 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1118 .addGroup(layout.createSequentialGroup()
1119 .addContainerGap()
1120 .addComponent(jCheckBox5))
1121 .addGroup(layout.createSequentialGroup()
1122 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1123 .addComponent(jLabel3)
1124 .addComponent(jLabel2))
1125 .addGap(18, 18, 18)
1126 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
1127 .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
1128 .addComponent(jTextField5)))
1129 .addGroup(layout.createSequentialGroup()
1130 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
1131 .addComponent(jLabel6)
1132 .addComponent(jLabel4))
1133 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
1134 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1135 .addGroup(layout.createSequentialGroup()
1136 .addGap(19, 19, 19)
1137 .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
1138 .addGroup(layout.createSequentialGroup()
1139 .addComponent(jButton1)
1140 .addGap(18, 18, 18)
1141 .addComponent(jButton2))
1142 .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
1143 .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
1144 .addGroup(layout.createSequentialGroup()
1145 .addGap(82, 82, 82)
1146 .addComponent(jLabel7))
1147 .addGroup(layout.createSequentialGroup()
1148 .addContainerGap()
1149 .addComponent(jCheckBox1))
1150 .addGroup(layout.createSequentialGroup()
1151 .addContainerGap()
1152 .addComponent(jCheckBox2))
1153 .addGroup(layout.createSequentialGroup()
1154 .addContainerGap()
1155 .addComponent(jCheckBox3))
1156 .addGroup(layout.createSequentialGroup()
1157 .addContainerGap()
1158 .addComponent(jCheckBox4)))
1159 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1160 .addGroup(layout.createSequentialGroup()
1161 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1162 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
1163 .addGap(276, 276, 276)
1164 .addComponent(jLabel9))
1165 .addGroup(layout.createSequentialGroup()
1166 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1167 .addGroup(layout.createSequentialGroup()
1168 .addGap(184, 184, 184)
1169 .addComponent(jButton3)
1170 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
1171 .addComponent(jButton4)
1172 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1173 .addComponent(jButton5)
1174 .addGap(484, 484, 484))
1175 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
1176 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1177 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
1178 .addGap(458, 458, 458)))
1179 .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 597, javax.swing.GroupLayout.PREFERRED_SIZE))))
1180 .addGroup(layout.createSequentialGroup()
1181 .addGap(152, 152, 152)
1182 .addComponent(jLabel1))
1183 );
1184 layout.setVerticalGroup(
1185 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1186 .addGroup(layout.createSequentialGroup()
1187 .addContainerGap()
1188 .addComponent(jLabel1)
1189 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1190 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
1191 .addComponent(jLabel2)
1192 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
1193 .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
1194 .addComponent(jLabel9))
1195 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
1196 .addGroup(layout.createSequentialGroup()
1197 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
1198 .addComponent(jLabel3)
1199 .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
1200 .addGap(18, 18, 18)
1201 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
1202 .addComponent(jLabel4)
1203 .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
1204 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
1205 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
1206 .addComponent(jButton1)
1207 .addComponent(jButton2))
1208 .addGap(18, 18, 18)
1209 .addComponent(jLabel7)
1210 .addGap(8, 8, 8)
1211 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
1212 .addComponent(jLabel6)
1213 .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
1214 .addGap(18, 18, 18)
1215 .addComponent(jLabel8)
1216 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1217 .addComponent(jCheckBox1)
1218 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1219 .addComponent(jCheckBox2)
1220 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1221 .addComponent(jCheckBox3)
1222 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1223 .addComponent(jCheckBox4)
1224 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1225 .addComponent(jCheckBox5))
1226 .addGroup(layout.createSequentialGroup()
1227 .addGap(12, 12, 12)
1228 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
1229 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
1230 .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
1231 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
1232 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
1233 .addComponent(jButton3)
1234 .addComponent(jButton4)
1235 .addComponent(jButton5))))
1236 .addContainerGap(97, Short.MAX_VALUE))
1237 );
1238
1239 pack();
1240 }// </editor-fold>
1241
1242 private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
1243 // TODO add your handling code here:
1244 }
1245
1246 private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
1247 // TODO add your handling code here:
1248 }
1249
1250 private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
1251 // TODO add your handling code here:
1252 }
1253
1254 private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {
1255 // TODO add your handling code here:
1256 }
1257
1258 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
1259 // TODO add your handling code here:
1260 }
1261
1262 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
1263 // TODO add your handling code here:
1264 }
1265
1266 /**
1267 * @param args the command line arguments
1268 */
1269 public static void main(String args[]) {
1270 /*
1271 * Set the Nimbus look and feel
1272 */
1273 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
1274 /*
1275 * If Nimbus (introduced in Java SE 6) is not available, stay with the
1276 * default look and feel. For details see
1277 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
1278 */
1279 try {
1280 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
1281 if ("Nimbus".equals(info.getName())) {
1282 javax.swing.UIManager.setLookAndFeel(info.getClassName());
1283 break;
1284 }
1285 }
1286 } catch (ClassNotFoundException ex) {
1287 java.util.logging.Logger.getLogger(form_.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1288 } catch (InstantiationException ex) {
1289 java.util.logging.Logger.getLogger(form_.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1290 } catch (IllegalAccessException ex) {
1291 java.util.logging.Logger.getLogger(form_.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1292 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
1293 java.util.logging.Logger.getLogger(form_.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1294 }
1295 //</editor-fold>
1296
1297 /*
1298 * Create and display the form
1299 */
1300 java.awt.EventQueue.invokeLater(new Runnable() {
1301
1302 public void run() {
1303 new form_().setVisible(true);
1304 }
1305 });
1306 }
1307 // Variables declaration - do not modify
1308 private javax.swing.JButton jButton1;
1309 private javax.swing.JButton jButton2;
1310 private javax.swing.JButton jButton3;
1311 private javax.swing.JButton jButton4;
1312 private javax.swing.JButton jButton5;
1313 private javax.swing.JCheckBox jCheckBox1;
1314 private javax.swing.JCheckBox jCheckBox2;
1315 private javax.swing.JCheckBox jCheckBox3;
1316 private javax.swing.JCheckBox jCheckBox4;
1317 private javax.swing.JCheckBox jCheckBox5;
1318 private javax.swing.JComboBox jComboBox1;
1319 private javax.swing.JLabel jLabel1;
1320 private javax.swing.JLabel jLabel2;
1321 private javax.swing.JLabel jLabel3;
1322 private javax.swing.JLabel jLabel4;
1323 private javax.swing.JLabel jLabel5;
1324 private javax.swing.JLabel jLabel6;
1325 private javax.swing.JLabel jLabel7;
1326 private javax.swing.JLabel jLabel8;
1327 private javax.swing.JLabel jLabel9;
1328 private javax.swing.JScrollPane jScrollPane1;
1329 private javax.swing.JScrollPane jScrollPane2;
1330 private javax.swing.JTable jTable1;
1331 private javax.swing.JTable jTable2;
1332 private javax.swing.JTextField jTextField1;
1333 private javax.swing.JTextField jTextField2;
1334 private javax.swing.JTextField jTextField3;
1335 private javax.swing.JTextField jTextField4;
1336 private javax.swing.JTextField jTextField5;
1337 private javax.swing.JToolBar jToolBar1;
1338 // End of variables declaration