houzhongjian
2024-11-07 a874b928e16320839315b9abcdf2cece1229a424
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.TargetRecognition;
H 2 import javax.swing.JFrame;
3 import javax.swing.JPanel;
4 import javax.swing.JLabel;
5 import javax.swing.JOptionPane;
6 import javax.swing.JTextField;
7 import javax.swing.SwingUtilities;
8 import com.sun.jna.Pointer;
9 import com.iailab.netsdk.common.DateChooserJButtonEx;
10 import com.iailab.netsdk.common.FunctionList;
11 import com.iailab.netsdk.common.Res;
12 import com.iailab.netsdk.demo.module.DotmatrixScreenModule;
13 import com.iailab.netsdk.demo.module.LoginModule;
14 import com.iailab.netsdk.lib.NetSDKLib;
15 import com.iailab.netsdk.lib.ToolKits;
16 import com.iailab.netsdk.lib.NetSDKLib.LLong;
17 import com.iailab.netsdk.lib.NetSDKLib.NET_CTRL_SET_PARK_INFO;
18
19 import javax.swing.JButton;
20 import javax.swing.JComboBox;
21 import javax.swing.ButtonGroup;
22 import javax.swing.DefaultComboBoxModel;
23 import javax.swing.JRadioButton;
24 import java.awt.event.ActionListener;
25 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.io.UnsupportedEncodingException;
28 import java.awt.event.ActionEvent;
29 import javax.swing.JPasswordField;
30 import javax.swing.border.TitledBorder;
31 import javax.swing.UIManager;
32 import java.awt.Color;
33 /**
34  * 
35  * @author 119178
36  * 点阵屏下发demo
37  */
38 public class LatticeScreen {
39
40     
41     // 设备断线通知回调
42     private  DisConnect disConnect  = new DisConnect();
43         
44     // 网络连接恢复
45     private  HaveReConnect haveReConnect = new HaveReConnect(); 
46     private JFrame frame;
47     private JTextField textField;
48     private JTextField textField_1;
49     private JTextField textField_2;
50     private JTextField textField_4;
51     private JTextField textField_5;
52     private JTextField textField_6;
53     private JTextField textField_7;
54     private JTextField textField_8;
55     private JTextField textField_9;
56     private JComboBox comboBox;
57     private JComboBox comboBox_1;
58     private JRadioButton rdbtnNewRadioButton;
59     private JRadioButton rdbtnNewRadioButton_1;
60     
61     private DateChooserJButtonEx startTime;
62     private DateChooserJButtonEx EndTime;
63     private JPasswordField passwordField;
64     
65     private JButton btnNewButton ;
66     private JButton btnNewButton_1 ;
67     private JButton btnNewButton_2 ;
68     private JTextField textField_3;
69     private JTextField textField_10;
70     private JTextField textField_11;
71
72     /**
73      * Launch the application.
74      */
75     public static void main(String[] args) {
76         SwingUtilities.invokeLater(new Runnable() {
77             public void run() {
78                 LatticeScreen demo = new LatticeScreen();
79                 demo.frame.setVisible(true);
80             }
81         });
82     }
83
84     /**
85      * Create the application.
86      */
87     public LatticeScreen() {
88         LoginModule.init(disConnect, haveReConnect);   // 打开工程,初始化
89         initialize();
90         // 注册窗体清出事件
91         frame.addWindowListener(new WindowAdapter() {
92             public void windowClosing(WindowEvent e) {
93                 LoginModule.logout();    // 退出
94                 LoginModule.cleanup();   // 关闭工程,释放资源
95                 frame.dispose();
96                 // 返回主菜单
97                 SwingUtilities.invokeLater(new Runnable() {
98                     public void run() {
99                         FunctionList demo = new FunctionList();
100                         demo.setVisible(true);
101                     }
102                 });
103             }
104         });
105     }
106
107 /////////////////面板///////////////////
108 // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数
109 private  class DisConnect implements NetSDKLib.fDisConnect {
110 public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
111 System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort);
112 // 断线提示
113 SwingUtilities.invokeLater(new Runnable() {
114     public void run() {
115         frame.setTitle(Res.string().getTargetRecognition() + " : " + Res.string().getDisConnectReconnecting());
116     }
117 });
118 }
119 }
120
121 // 网络连接恢复,设备重连成功回调
122 // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数
123 private  class HaveReConnect implements NetSDKLib.fHaveReConnect {
124 public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
125 System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort);
126
127 // 重连提示
128 SwingUtilities.invokeLater(new Runnable() {
129     public void run() {
130         frame.setTitle(Res.string().getTargetRecognition() + " : " + Res.string().getOnline());
131     }
132 });
133 }
134 }
135     
136     /**
137      * Initialize the contents of the frame.
138      */
139     private void initialize() {
140         frame = new JFrame();
141         frame.setTitle(Res.string().getmatrixScreen());
142         frame.setBounds(200, 200, 807, 578);
143         //frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
144         frame.getContentPane().setLayout(null); 
145             try {
146                         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
147                     } catch (Exception e) {
148                         e.printStackTrace();
149                     } 
150
151         final JPanel panel1 = new JPanel();
152         panel1.setBounds(10, 10, 100, 50);
153         
154         JPanel panel = new JPanel();
155         panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), Res.string().getLogin(), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
156         panel.setBounds(10, 10, 771, 40);
157         frame.getContentPane().add(panel);
158         panel.setLayout(null);
159         
160         JLabel lblNewLabel = new JLabel(Res.string().getDeviceIp()+":");
161         lblNewLabel.setBounds(26, 14, 54, 15);
162         panel.add(lblNewLabel);
163         
164         textField = new JTextField("172.24.31.178");
165         textField.setBounds(82, 11, 76, 21);
166         panel.add(textField);
167         textField.setColumns(10);
168         
169         JLabel lblNewLabel_1 = new JLabel(Res.string().getPort()+":");
170         lblNewLabel_1.setBounds(168, 14, 47, 15);
171         panel.add(lblNewLabel_1);
172         
173         textField_1 = new JTextField("37777");
174         textField_1.setBounds(217, 11, 76, 21);
175         panel.add(textField_1);
176         textField_1.setColumns(10);
177         
178         JLabel lblNewLabel_2 = new JLabel(Res.string().getUserName()+":");
179         lblNewLabel_2.setBounds(302, 14, 47, 15);
180         panel.add(lblNewLabel_2);
181         
182         textField_2 = new JTextField("admin");
183         textField_2.setBounds(351, 11, 76, 21);
184         panel.add(textField_2);
185         textField_2.setColumns(10);
186         
187         JLabel lblNewLabel_3 = new JLabel(Res.string().getPassword()+":");
188         lblNewLabel_3.setBounds(435, 14, 38, 15);
189         panel.add(lblNewLabel_3);
190         
191         passwordField = new JPasswordField("admin123");
192         passwordField.setBounds(476, 11, 89, 21);
193         panel.add(passwordField);
194         
195         btnNewButton = new JButton(Res.string().getLogin());
196         btnNewButton.addActionListener(new ActionListener() {
197             public void actionPerformed(ActionEvent e) {
198                 if(LoginModule.login(textField.getText(), 
199                         Integer.parseInt(textField_1.getText()), 
200                         textField_2.getText(), 
201                         new String(passwordField.getPassword()))) {
202                     btnNewButton.setEnabled(false);
203                     btnNewButton_1.setEnabled(true);
204                     btnNewButton_2.setEnabled(true);
205                     
206                     textField.setEnabled(true);;
207                     textField_1.setEditable(true);;
208                     textField_2.setEnabled(true);
209                     textField_3.setEnabled(true);
210                     textField_4.setEnabled(true);
211                     textField_5.setEnabled(true);
212                     textField_6.setEnabled(true);
213                     textField_7.setEnabled(true);
214                     textField_8.setEnabled(true);
215                     textField_9.setEnabled(true);
216                     textField_10.setEnabled(true);
217                     textField_11.setEnabled(true);
218                     comboBox.setEnabled(true);
219                     comboBox_1.setEnabled(true);
220                     rdbtnNewRadioButton.setEnabled(true);
221                     rdbtnNewRadioButton_1.setEnabled(true);
222                     startTime.setEnabled(true);
223                     EndTime.setEnabled(true);
224                     passwordField.setEnabled(true);
225                 }else{
226                     JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
227                 }
228             }
229         });
230         btnNewButton.setBounds(584, 10, 76, 23);
231         panel.add(btnNewButton);
232         btnNewButton.setEnabled(true);
233         
234         btnNewButton_1 = new JButton(Res.string().getLogout());
235         btnNewButton_1.addActionListener(new ActionListener() {
236             public void actionPerformed(ActionEvent e) {
237                 LoginModule.logout();
238                 btnNewButton.setEnabled(true);
239                 btnNewButton_1.setEnabled(false);
240                 btnNewButton_2.setEnabled(false);
241                 
242                 textField.setEnabled(false);;
243                 textField_1.setEditable(false);;
244                 textField_2.setEnabled(false);
245                 textField_3.setEnabled(false);
246                 textField_4.setEnabled(false);
247                 textField_5.setEnabled(false);
248                 textField_6.setEnabled(false);
249                 textField_7.setEnabled(false);
250                 textField_8.setEnabled(false);
251                 textField_9.setEnabled(false);
252                 textField_10.setEnabled(false);
253                 textField_11.setEnabled(false);
254                 comboBox.setEnabled(false);
255                 comboBox_1.setEditable(false);
256                 rdbtnNewRadioButton.setEnabled(false);
257                 rdbtnNewRadioButton_1.setEnabled(false);
258                 startTime.setEnabled(true);
259                 EndTime.setEnabled(true);
260                 passwordField.setEnabled(true);
261             }
262         });
263         btnNewButton_1.setBounds(678, 10, 76, 23);
264         panel.add(btnNewButton_1);
265         btnNewButton_1.setEnabled(false);
266         
267         JPanel panel_1 = new JPanel();
268         panel_1.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
269         panel_1.setBounds(10, 56, 771, 474);
270         frame.getContentPane().add(panel_1);
271         panel_1.setLayout(null);
272         
273         JLabel lblNewLabel_4 = new JLabel(Res.string().getPassingState()+":");
274         lblNewLabel_4.setBounds(71, 26, 95, 21);
275         panel_1.add(lblNewLabel_4);
276         
277         comboBox = new JComboBox();
278         comboBox.setEnabled(false);
279         comboBox.setModel(new DefaultComboBoxModel(new String[] {Res.string().getPassingCar(), Res.string().getNoCar()}));
280         comboBox.setBounds(176, 26, 131, 21);
281         panel_1.add(comboBox);
282         
283         JLabel lblNewLabel_5 = new JLabel(Res.string().getInTime()+":");
284         lblNewLabel_5.setBounds(391, 29, 102, 15);
285         panel_1.add(lblNewLabel_5);
286         
287         startTime=new DateChooserJButtonEx();
288         startTime.setEnabled(false);
289         startTime.setBounds(503, 26, 131, 21);
290         panel_1.add(startTime);
291         
292         JLabel lblNewLabel_6 = new JLabel(Res.string().getOutTime()+":");
293         lblNewLabel_6.setBounds(391, 84, 102, 15);
294         panel_1.add(lblNewLabel_6);
295         
296         EndTime=new DateChooserJButtonEx();
297         EndTime.setEnabled(false);
298         EndTime.setBounds(503, 81, 131, 21);
299         panel_1.add(EndTime);
300         
301         JLabel lblNewLabel_7 = new JLabel(Res.string().getPlateNumber()+":");
302         lblNewLabel_7.setBounds(71, 84, 95, 15);
303         panel_1.add(lblNewLabel_7);
304         
305         textField_4 = new JTextField();
306         textField_4.setEnabled(false);
307         textField_4.setBounds(176, 81, 131, 21);
308         panel_1.add(textField_4);
309         textField_4.setColumns(10);
310         
311         JLabel lblNewLabel_8 = new JLabel(Res.string().getCarOwner()+":");
312         lblNewLabel_8.setBounds(77, 142, 89, 15);
313         panel_1.add(lblNewLabel_8);
314         
315         textField_5 = new JTextField();
316         textField_5.setEnabled(false);
317         textField_5.setBounds(176, 139, 131, 21);
318         panel_1.add(textField_5);
319         textField_5.setColumns(10);
320         
321         JLabel lblNewLabel_9 = new JLabel(Res.string().getParkingTime()+":");
322         lblNewLabel_9.setBounds(391, 133, 102, 15);
323         panel_1.add(lblNewLabel_9);
324         
325         textField_6 = new JTextField();
326         textField_6.setEnabled(false);
327         textField_6.setBounds(503, 130, 131, 21);
328         panel_1.add(textField_6);
329         textField_6.setColumns(10);
330         
331         JLabel lblNewLabel_10 = new JLabel(Res.string().getUserType()+":");
332         lblNewLabel_10.setBounds(71, 198, 95, 15);
333         panel_1.add(lblNewLabel_10);
334         
335         comboBox_1 = new JComboBox();
336         comboBox_1.setEnabled(false);
337         comboBox_1.setModel(new DefaultComboBoxModel(new String[] {Res.string().getMonthlyCardUser()
338                 ,Res.string().getAnnualCardUser(), Res.string().getLongTermUser(), Res.string().getTemporaryUser()}));
339         comboBox_1.setBounds(176, 195, 131, 21);
340         panel_1.add(comboBox_1);
341         
342         JLabel lblNewLabel_11 = new JLabel(Res.string().getParkingCharge());
343         lblNewLabel_11.setBounds(391, 178, 102, 15);
344         panel_1.add(lblNewLabel_11);
345         
346         textField_7 = new JTextField();
347         textField_7.setEnabled(false);
348         textField_7.setBounds(503, 175, 131, 21);
349         panel_1.add(textField_7);
350         textField_7.setColumns(10);
351         
352         JLabel lblNewLabel_12 = new JLabel(Res.string().getDaysDue());
353         lblNewLabel_12.setBounds(71, 253, 95, 15);
354         panel_1.add(lblNewLabel_12);
355         
356         textField_8 = new JTextField();
357         textField_8.setEnabled(false);
358         textField_8.setBounds(176, 250, 131, 21);
359         panel_1.add(textField_8);
360         textField_8.setColumns(10);
361         
362         JLabel lblNewLabel_13 = new JLabel(Res.string().getRemainingParkingSpaces());
363         lblNewLabel_13.setBounds(391, 215, 102, 15);
364         panel_1.add(lblNewLabel_13);
365         
366         textField_9 = new JTextField();
367         textField_9.setEnabled(false);
368         textField_9.setBounds(503, 212, 131, 21);
369         panel_1.add(textField_9);
370         textField_9.setColumns(10);
371         
372         rdbtnNewRadioButton = new JRadioButton(Res.string().getVehiclesNotAllowedToPass());
373         rdbtnNewRadioButton.setEnabled(false);
374         rdbtnNewRadioButton.setBounds(367, 249, 155, 23);
375         panel_1.add(rdbtnNewRadioButton);
376         
377         rdbtnNewRadioButton_1 = new JRadioButton(Res.string().getAllowedVehiclesToPass());
378         rdbtnNewRadioButton_1.setEnabled(false);
379         rdbtnNewRadioButton_1.setBounds(524, 249, 162, 23);
380         panel_1.add(rdbtnNewRadioButton_1);
381         
382         ButtonGroup group=new ButtonGroup();
383         group.add(rdbtnNewRadioButton);
384         group.add(rdbtnNewRadioButton_1);
385         
386         btnNewButton_2 = new JButton(Res.string().getSetUp());
387         btnNewButton_2.addActionListener(new ActionListener() {
388             public void actionPerformed(ActionEvent e) {
389                 int emType=NetSDKLib.CtrlType.CTRLTYPE_CTRL_SET_PARK_INFO;
390                 
391                 NET_CTRL_SET_PARK_INFO msg=new NET_CTRL_SET_PARK_INFO();
392                 
393                 msg.szPlateNumber=textField_4.getText().getBytes();
394                 
395                 if(!textField_6.getText().equals("")) {
396                 msg.nParkTime=Integer.parseInt(textField_6.getText());
397                 }else {
398                     msg.nParkTime=0;
399                 }
400                 
401                 msg.szMasterofCar=textField_5.getText().getBytes();
402                 
403                 if(comboBox_1.getSelectedItem().equals(Res.string().getMonthlyCardUser())) {
404                     msg.szUserType="monthlyCardUser".getBytes();
405                 }
406                 else if(comboBox_1.getSelectedItem().equals(Res.string().getAnnualCardUser())){
407                     msg.szUserType="yearlyCardUser".getBytes();
408                 }
409                 else if(comboBox_1.getSelectedItem().equals(Res.string().getLongTermUser())){
410                     msg.szUserType="longTimeUser".getBytes();
411                 }
412                 else if(comboBox_1.getSelectedItem().equals(Res.string().getTemporaryUser())){
413                     msg.szUserType="casualUser".getBytes();
414                 }
415                 
416                 if(!textField_8.getText().equals("")) {
417                 msg.nRemainDay=Integer.parseInt(textField_8.getText());
418                 }else {
419                     msg.nRemainDay=0;
420                 }
421                                 
422                 if(rdbtnNewRadioButton.isSelected()) {
423                     msg.nPassEnable=0;
424                     }else if(rdbtnNewRadioButton_1.isSelected()){
425                         msg.nPassEnable=1;
426                     }
427                 String InTime=startTime.getText().toString();// 车辆入场时间
428                 String[] InTimes = InTime.split("-");
429                 
430                 msg.stuInTime.dwYear = (short)Integer.parseInt(InTimes[0]);
431                 msg.stuInTime.dwMonth = (byte)Integer.parseInt(InTimes[1]);
432                 msg.stuInTime.dwDay = (byte)Integer.parseInt(InTimes[2]);
433                 
434                 String OutTime=EndTime.getText().toString();// 车辆出场时间
435                 String[] OutTimes = OutTime.split("-");
436                 
437                 msg.stuOutTime.dwYear = (short)Integer.parseInt(OutTimes[0]);
438                 msg.stuOutTime.dwMonth = (byte)Integer.parseInt(OutTimes[1]);
439                 msg.stuOutTime.dwDay = (byte)Integer.parseInt(OutTimes[2]);
440                 
441                 //msg.stuInTime.setTime(2019, 7, 9, 10, 45, 0);     // 车辆入场时间
442                 //msg.stuOutTime.setTime(2019, 7, 9, 10, 52, 0); // 车辆出场时间
443                 try {
444                     msg.szParkCharge=textField_7.getText().getBytes("GBK");
445                 } catch (UnsupportedEncodingException e2) {
446                     // TODO Auto-generated catch block
447                     e2.printStackTrace();
448                 }
449                 
450                 if(!textField_9.getText().equals("")) {
451                     msg.nRemainSpace=Integer.parseInt(textField_9.getText());
452                     }else {
453                         msg.nRemainSpace=0;
454                     }
455                 
456                 /*
457                  * if(rdbtnNewRadioButton.isSelected()) { msg.nPassEnable=1; }else
458                  * if(rdbtnNewRadioButton_1.isSelected()){ msg.nPassEnable=0; }
459                  */
460                 if(comboBox.getSelectedItem().equals(Res.string().getPassingCar())) {
461                     msg.emCarStatus=1;
462                 }
463                 else if(comboBox.getSelectedItem().equals(Res.string().getNoCar())){
464                     msg.emCarStatus=2;
465                 }
466                 
467                 try {
468                     msg.szSubUserType=textField_3.getText().getBytes("GBK");
469                 } catch (UnsupportedEncodingException e1) {
470                     // TODO Auto-generated catch block
471                     e1.printStackTrace();
472                 }
473                 try {
474                     msg.szRemarks=textField_10.getText().getBytes("GBK");
475                 } catch (UnsupportedEncodingException e1) {
476                     // TODO Auto-generated catch block
477                     e1.printStackTrace();
478                 }
479                 try {
480                     msg.szCustom=textField_11.getText().getBytes("GBK");
481                 } catch (UnsupportedEncodingException e1) {
482                     // TODO Auto-generated catch block
483                     e1.printStackTrace();
484                 }
485                 
486                 msg.write();
487                 boolean ret=DotmatrixScreenModule.setDotmatrixScreen(emType, msg);
488                 if(ret) {
489                     JOptionPane.showMessageDialog(panel1, Res.string().getSetUpSuccess());
490                 }else {
491                     JOptionPane.showMessageDialog(panel1, Res.string().getSetUpFailed());
492                 }
493             }
494         });
495         btnNewButton_2.setBounds(618, 441, 93, 23);
496         panel_1.add(btnNewButton_2);
497         btnNewButton_2.setEnabled(false);    
498         
499         JLabel label = new JLabel(Res.string().getCostomUserInfo()+":");
500         label.setBounds(58, 309, 119, 21);
501         panel_1.add(label);
502         
503         JLabel label_1 = new JLabel(Res.string().getRemarksInfo()+":");
504         label_1.setBounds(58, 350, 97, 21);
505         panel_1.add(label_1);
506         
507         JLabel label_2 = new JLabel(Res.string().getCostomInfo()+":");
508         label_2.setBounds(60, 394, 95, 21);
509         panel_1.add(label_2);
510         
511         textField_3 = new JTextField();
512         textField_3.setEnabled(false);
513         textField_3.setColumns(10);
514         textField_3.setBounds(187, 306, 460, 28);
515         panel_1.add(textField_3);
516         
517         textField_10 = new JTextField();
518         textField_10.setEnabled(false);
519         textField_10.setColumns(10);
520         textField_10.setBounds(187, 347, 460, 28);
521         panel_1.add(textField_10);
522         
523         textField_11 = new JTextField();
524         textField_11.setEnabled(false);
525         textField_11.setColumns(10);
526         textField_11.setBounds(187, 391, 460, 28);
527         panel_1.add(textField_11);
528     }
529 }