-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrmState.java
More file actions
493 lines (407 loc) · 12.4 KB
/
FrmState.java
File metadata and controls
493 lines (407 loc) · 12.4 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
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.awt.event.*;
import java.util.*;
import appsetting.*;
import screensetting.*;
import myUtility.*;
import ReportUtility.*;
class FrmState extends JFrame implements ActionListener
{
JPanel pnlUI;
JPanel pnlUIReport;
JPanel pnlApply;
JButton btnApply;
JPanel pnlNew;
JButton btnNew;
JPanel pnlSave;
JButton btnSave;
JPanel pnlView;
JButton btnView;
JPanel pnlEdit;
JButton btnEdit;
JPanel pnlUpdate;
JButton btnUpdate;
JPanel pnlDelete;
JButton btnDelete;
JPanel pnlCancel;
JButton btnCancel;
JPanel pnlReport;
JButton btnReport;
JPanel pnlClose;
JButton btnClose;
JPanel pnlCountryUpdate;
JComboBox cmbCountryUpdate;
JLabel lblCountryUpdate;
JPanel pnlStateUpdate;
JLabel lblStateUpdate;
JComboBox cmbStateUpdate;
JComboBox cmbCountry;
JComboBox lblCountry;
JLabel lblProgramHeading;
JLabel lblStateID ;
JLabel lblStateName;
JTextField txtStateID;
JTextField txtStateName;
JButton btnNewDoc;
JButton btnRefreshDoc;
int Rcols;
ReportTool tool;
int vCountryID=0;
ScreenDesign2 myUI;
ButtonState bst;
clsButtonManagement2 cbm;
FrmState()
{
setSize(1950,1200);
setLocation(1,1);
setLayout(null);
setBackground(ColorSetting.getBackColorFrame());
setTitle("Form Designing");
setExtendedState(getExtendedState()|JFrame.MAXIMIZED_BOTH );
myUI = new ScreenDesign2();
add(myUI);
pnlUIReport = myUI.getUIReportPanel();
tool = new ReportTool(500,500);
tool.setBounds(10,10,500,300);
pnlUIReport.add(tool);
UISetting.setArea(pnlUIReport,520,460);
pnlUI = myUI.getUIPanel();
pnlUI.setLayout(null);
UISetting.setArea(pnlUI,500,270);
pnlNew = myUI.getNewPanel();
btnNew = myUI.getNewButton();
btnNew.addActionListener(this);
pnlSave = myUI.getSavePanel();
btnSave = myUI.getSaveButton();
btnSave.addActionListener(this);
pnlCancel = myUI.getCancelPanel();
btnCancel = myUI.getCancelButton();
btnCancel.addActionListener(this);
pnlReport = myUI.getReportPanel();
btnReport = myUI.getReportButton();
btnReport.addActionListener(this);
pnlClose = myUI.getClosePanel();
btnClose = myUI.getCloseButton();
btnClose.addActionListener(this);
pnlCountryUpdate = myUI.getCombo1Panel();
lblCountryUpdate = myUI.getCombo1Label();
lblCountryUpdate.setText("Country List!!!");
cmbCountryUpdate = myUI.getCombo1ComboBox();
cmbCountryUpdate.addActionListener(this);
pnlStateUpdate = myUI.getCombo2Panel();
lblStateUpdate = myUI.getCombo2Label();
lblStateUpdate.setText("State List!!!");
cmbStateUpdate = myUI.getCombo2ComboBox();
cmbStateUpdate.addActionListener(this);
pnlView = myUI.getViewPanel();
btnView = myUI.getViewButton();
btnView.addActionListener(this);
pnlReport = myUI.getReportPanel();
btnReport = myUI.getReportButton();
btnReport.addActionListener(this);
pnlApply = myUI.getApplyPanel();
btnApply = myUI.getApplyButton();
btnApply.addActionListener(this);
pnlEdit = myUI.getEditPanel();
btnEdit = myUI.getEditButton();
btnEdit.addActionListener(this);
pnlDelete = myUI.getDeletePanel();
btnDelete = myUI.getDeleteButton();
btnDelete.addActionListener(this);
pnlUpdate = myUI.getUpdatePanel();
btnUpdate = myUI.getUpdateButton();
btnUpdate.addActionListener(this);
pnlUIReport = myUI.getUIReportPanel();
lblProgramHeading = myUI.getProgramHeadingLabel();
new BlinkLabel(lblProgramHeading,800).start();
lblStateID = new JLabel("State ID : ");
lblStateID.setLayout(null);
lblStateID.setBounds(70,40,200,50);
lblStateID.setFont(new Font("Basic", Font.BOLD, 18));
pnlUI.add(lblStateID);
txtStateID = new JTextField();
txtStateID.setLayout(null);
txtStateID.setBounds(230,40,200,50);
txtStateID.setFont(new Font("Basic", Font.BOLD, 18));
pnlUI.add(txtStateID);
lblStateName = new JLabel("State Name : ");
lblStateName.setLayout(null);
lblStateName.setBounds(70,110,200,50);
lblStateName.setFont(new Font("Basic", Font.BOLD, 18));
pnlUI.add(lblStateName);
txtStateName = new JTextField();
txtStateName.setLayout(null);
txtStateName.setBounds(230,110,200,50);
txtStateName.setFont(new Font("Basic", Font.BOLD, 18));
pnlUI.add(txtStateName);
lblStateName = new JLabel("Country : ");
lblStateName.setLayout(null);
lblStateName.setBounds(70,180,200,50);
lblStateName.setFont(new Font("Basic", Font.BOLD, 18));
pnlUI.add(lblStateName);
cmbCountry = new JComboBox();
cmbCountry.setBounds(230,180,200,50);
cmbCountry.setFont(new Font("Basic", Font.BOLD, 18));
pnlUI.add(cmbCountry);
ImageIcon imgIcon = new ImageIcon("imagesrc\\imgNewDoc.png");
Image image = imgIcon.getImage();
Image newimage = image.getScaledInstance(48,45,java.awt.Image.SCALE_SMOOTH);
Icon imgNewDoc = new ImageIcon(newimage);
btnNewDoc = new JButton(imgNewDoc);
btnNewDoc.setBounds(436,180,43,50);
btnNewDoc.addActionListener(this);
btnNewDoc.setBackground(Color.WHITE);
pnlUI.add(btnNewDoc);
ImageIcon imgIcon2 = new ImageIcon("imagesrc\\imgRefreshDoc.png");
Image image2 = imgIcon2.getImage();
Image refreshimage2 = image2.getScaledInstance(48,45,java.awt.Image.SCALE_SMOOTH);
Icon imgRefreshDoc = new ImageIcon(refreshimage2);
btnRefreshDoc = new JButton(imgRefreshDoc);
btnRefreshDoc.setBounds(436,180,43,50);
btnRefreshDoc.setBackground(Color.WHITE);
btnRefreshDoc.addActionListener(this);
pnlUI.add(btnRefreshDoc);
//setDefaultOperation();
bst = new ButtonState();
cbm = new clsButtonManagement2();
automateButtons();
bst.setButtonState(ButtonState.InitialState);
cbm.showButtonsOnUI(bst);
addCountryRecords(cmbCountry);
show();
createReport();
}
void automateButtons()
{
cbm.manageNewPanel(pnlNew);
cbm.manageViewPanel(pnlView);
cbm.manageUIPanel(pnlUI);
cbm.manageUIReportPanel(pnlUIReport);
cbm.manageClosePanel(pnlClose);
//cbm.manageEntryPanel(pnlEntry);
//cbm.manageDataReportPanel(pnlDataReport);
cbm.manageSavePanel(pnlSave);
cbm.manageViewPanel(pnlView);
cbm.manageEditPanel(pnlEdit);
cbm.manageUpdatePanel(pnlUpdate);
cbm.manageDeletePanel(pnlDelete);
cbm.manageCancelPanel(pnlCancel);
cbm.manageReportPanel(pnlReport);
cbm.manageApplyPanel(pnlApply);
cbm.manageCombo1Panel(pnlCountryUpdate);
cbm.manageCombo1Label(lblCountryUpdate);
cbm.manageCombo1(cmbCountryUpdate);
cbm.manageCombo2Panel(pnlStateUpdate);
cbm.manageCombo2Label(lblStateUpdate);
cbm.manageCombo2(cmbStateUpdate);
}
void setDefaultOperation()
{
PanelState.enabledComponents(pnlNew);
PanelState.enabledComponents(pnlView);
PanelState.enabledComponents(pnlReport);
PanelState.disabledComponents(pnlUI);
}
void initUI()
{
txtStateID.setText("0");
txtStateName.setText("");
txtStateName.requestFocus();
cmbCountry.setSelectedIndex(0);
}
clsState readUI()
{
clsState temp = new clsState();
temp.setStateID(Integer.parseInt(txtStateID.getText()));
temp.setStateName(txtStateName.getText());
temp.setCountryID(vCountryID);
return(temp);
}
void writeUI(clsState temp)
{
txtStateID.setText(String.valueOf(temp.getStateID()));
txtStateName.setText(temp.getStateName());
clsLocationManagement2 temp1 = clsLocationManagement2.getLocationInfo(temp.getStateID());
vCountryID=temp1.getCountryID();
cmbCountry.setSelectedItem(temp1.getCountryName());
}
void createReport()
{
setColumnsHeading();
setColumnsAlignment();
setColumnsWidth();
}
void setColumnsHeading()
{
Rcols=0;
Rcols+=tool.addNewColumn("StateID");
Rcols+=tool.addNewColumn("StateName");
Rcols+=tool.addNewColumn("CountryName");
}
void setColumnsAlignment()
{
tool.setColumnAlignment(0,ReportTool.ALIGN_CENTER);
tool.setColumnAlignment(1,ReportTool.ALIGN_CENTER);
tool.setColumnAlignment(2,ReportTool.ALIGN_CENTER);
}
void setColumnsWidth()
{
tool.setColumnWidth("StateID",80);
tool.setColumnWidth("StateName",200);
tool.setColumnWidth("CountryName",200);
}
void setColumnsData()
{
tool.removeAllRows();
clsStateReport1 Data[]=clsStateReport1.getStateReport1Info();
for(int i=0;i<Data.length;i++)
{
Object Objectdata[]=new Object[Rcols];
Objectdata[0]=i+1;
Objectdata[1]=Data[i].getStateName();
Objectdata[2]=Data[i].getCountryName();
tool.addNewRow(Objectdata);
}
}
void addCountryRecords(JComboBox temp)
{
temp.removeActionListener(this);
clsCountry.addCountryRecords(temp);
temp.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnNew)
{
initUI();
bst.setButtonState(ButtonState.NewState);
cbm.showButtonsOnUI(bst);
}
else if(ae.getSource() == btnView)
{
bst.setButtonState(ButtonState.ViewState);
cbm.showButtonsOnUI(bst);
addCountryRecords(cmbCountryUpdate);
//addStateRecords(cmbStateUpdate);
}
else if(ae.getSource() == btnSave)
{
clsState temp = readUI();
clsState.showState(temp);
if(clsState.isStateDulplicate(temp.getStateName()))
{
JOptionPane.showMessageDialog(null,"Entered State Already Exist......! ");
}
else
{
bst.setButtonState(ButtonState.SaveState);
cbm.showButtonsOnUI(bst);
clsState.addNewState(temp);
JOptionPane.showMessageDialog(null,"State Added Successfully....!");
}
}
else if(ae.getSource() == btnApply)
{
if(cmbCountryUpdate.getSelectedIndex() == 0 || cmbStateUpdate.getSelectedIndex() == 0)
{
JOptionPane.showMessageDialog(null,"Please Select Country or State Property....!");
}
else
{
String mStateName = (String)cmbStateUpdate.getSelectedItem();
int mStateID = clsState.getIDFromName(mStateName);
clsState temp=clsState.getStateInformation(mStateID);
clsState.showState(temp);
writeUI(temp);
bst.setButtonState(ButtonState.ApplyState);
cbm.showButtonsOnUI(bst);
}
}
else if(ae.getSource() == btnEdit)
{
bst.setButtonState(ButtonState.EditState);
cbm.showButtonsOnUI(bst);
}
else if(ae.getSource() == btnUpdate)
{
bst.setButtonState(ButtonState.UpdateState);
cbm.showButtonsOnUI(bst);
clsState temp = readUI();
clsState.updateState(temp);
PanelState.disabledComponents(pnlUI);
JOptionPane.showMessageDialog(null,"State Updated Successfully....!");
}
else if(ae.getSource() == btnDelete)
{
bst.setButtonState(ButtonState.DeleteState);
cbm.showButtonsOnUI(bst);
clsState temp = readUI();
clsState.deleteState(temp);
JOptionPane.showMessageDialog(null,"State Deleted Successfully....!");
}
else if(ae.getSource() == btnCancel)
{
bst.setButtonUniqueState(ButtonState.CancelState);
cbm.showButtonsOnUI(bst);
}
else if(ae.getSource() == cmbCountry)
{
if(cmbCountry.getSelectedIndex() == 0)
{
JOptionPane.showMessageDialog(null,"Please Select Country Properly...");
}
else
{
String mCountryName = (String)cmbCountry.getSelectedItem();
vCountryID = clsCountry.getIDFromName(mCountryName);
}
}
else if(ae.getSource() == cmbCountryUpdate)
{
if(cmbCountryUpdate.getSelectedIndex() == 0)
{
JOptionPane.showMessageDialog(null,"Please Select Country Properly...");
}
else
{
String mCountryName = (String)cmbCountryUpdate.getSelectedItem();
int mCountryID = clsCountry.getIDFromName(mCountryName);
addStateRecords(cmbStateUpdate,mCountryID);
}
}
else if(ae.getSource()==btnNewDoc)
{
btnNewDoc.setVisible(false);
btnRefreshDoc.setVisible(true);
FrmCountry A= new FrmCountry();
}
else if(ae.getSource()==btnRefreshDoc)
{
btnNewDoc.setVisible(true);
btnRefreshDoc.setVisible(false);
addCountryRecords(cmbCountry);
}
else if(ae.getSource()==btnReport)
{
bst.setButtonCommonState(ButtonState.ReportState);
cbm.showButtonsOnUI(bst);
setColumnsData();
}
else if(ae.getSource()==btnClose)
{
bst.setButtonCommonState(ButtonState.CloseReportState);
cbm.showButtonsOnUI(bst);
}
}
void addStateRecords(JComboBox temp, int mCountryID)
{
clsState.addStateRecords(temp,mCountryID);
}
public static void main(String args[])
{
FrmState F=new FrmState();
}
}