dengzedong
2024-12-19 85b2001c0ec2f1adc598db3bf47ad457dcca7074
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.Attendance;
H 2
3 import java.awt.BorderLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.event.WindowAdapter;
7 import java.awt.event.WindowEvent;
8
9 import javax.swing.JFrame;
10 import javax.swing.JOptionPane;
11 import javax.swing.JSplitPane;
12 import javax.swing.SwingUtilities;
13 import javax.swing.UIManager;
14
15 import com.sun.jna.Pointer;
16
17 import com.iailab.netsdk.common.FunctionList;
18 import com.iailab.netsdk.common.LoginPanel;
19 import com.iailab.netsdk.common.Res;
20 import com.iailab.netsdk.demo.module.AttendanceModule;
21 import com.iailab.netsdk.demo.module.LoginModule;
22 import com.iailab.netsdk.lib.NetSDKLib;
23 import com.iailab.netsdk.lib.NetSDKLib.LLong;
24 import com.iailab.netsdk.lib.ToolKits;
25
26 /**
27  * 考勤机Demo:包含门禁事件订阅、人员操作、信息操作
28  */
29 class AttendanceFrame  extends JFrame{
30     /**
31      * 
32      */
33     private static final long serialVersionUID = 1L;
34     
35     // 设备断线通知回调
36     private  DisConnect disConnect  = new DisConnect(); 
37     
38     // 获取界面窗口
39     private static JFrame frame = new JFrame();
40         
41     public AttendanceFrame(){
42         setTitle(Res.string().getAttendance());
43         setLayout(new BorderLayout());
44         pack();
45         setSize(800, 555);
46         setResizable(false);
47         setLocationRelativeTo(null);  
48         setDefaultCloseOperation(DISPOSE_ON_CLOSE);   // 释放窗体
49         
50         LoginModule.init(disConnect, null);   // 打开工程,初始化 
51
52         try {
53             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
54         } catch (Exception e) {
55             e.printStackTrace();
56         }
57         
58         loginPanel = new LoginPanel();
59         showPanel = new AttendanceShowPanel();
60         operatePanel = new AttendanceFunctionOperatePanel(showPanel);
61         
62         JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, loginPanel, operatePanel);
63         splitPane.setDividerSize(0);
64         splitPane.setBorder(null);
65         add(splitPane, BorderLayout.NORTH);
66         add(showPanel, BorderLayout.CENTER);
67         
68         loginPanel.addLoginBtnActionListener(new ActionListener() {
69             @Override
70             public void actionPerformed(ActionEvent e) {               
71                 if(loginPanel.checkLoginText()) {
72                     if(login()) {
73                         frame = ToolKits.getFrame(e);
74                         frame.setTitle(Res.string().getAttendance() + " : " + Res.string().getOnline());
75                     }
76                 }
77             }
78         });
79         
80         loginPanel.addLogoutBtnActionListener(new ActionListener() {        
81             @Override
82             public void actionPerformed(ActionEvent e) {
83                 SwingUtilities.invokeLater(new Runnable() {
84                     public void run() {
85                         logout();
86                     }
87                 });
88             }
89         });
90         
91         addWindowListener(new WindowAdapter() {
92             public void windowClosing(WindowEvent e) {
93                 AttendanceModule.stopRealLoadPicture();
94                 LoginModule.logout();
95                 LoginModule.cleanup();   // 关闭工程,释放资源
96                 dispose();    
97                 
98                 SwingUtilities.invokeLater(new Runnable() {
99                     public void run() {
100                         FunctionList demo = new FunctionList();
101                         demo.setVisible(true);
102                     }
103                 });
104             }
105         });
106     }
107     
108     // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数
109     private class DisConnect implements NetSDKLib.fDisConnect {
110         public DisConnect() { }
111         
112         public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
113             System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort);
114             // 断线提示
115             SwingUtilities.invokeLater(new Runnable() {
116                 public void run() {
117                     JOptionPane.showMessageDialog(null, Res.string().getDisConnect(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
118                     logout();
119                 }
120             });
121         }
122     }
123         
124     // 登录
125     public boolean login() {
126         if(LoginModule.login(loginPanel.ipTextArea.getText(), 
127                         Integer.parseInt(loginPanel.portTextArea.getText()), 
128                         loginPanel.nameTextArea.getText(), 
129                         new String(loginPanel.passwordTextArea.getPassword()))) {
130     
131             loginPanel.setButtonEnable(true);
132             operatePanel.setButtonEnable(true);
133             
134         } else {
135             JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
136             return false;
137         }
138         return true;
139     }
140         
141     // 登出
142     public void logout() {
143         AttendanceModule.stopRealLoadPicture();
144         LoginModule.logout();
145         
146         frame.setTitle(Res.string().getAttendance());
147         loginPanel.setButtonEnable(false);
148         operatePanel.setButtonEnable(false);
149         showPanel.clearup();
150     }
151     
152     private LoginPanel loginPanel;                            // 登陆面板
153     private AttendanceFunctionOperatePanel operatePanel;    // 操作面板
154     private AttendanceShowPanel showPanel;                    // 显示面板
155 }
156
157 public class Attendance {
158     public static void main(String[] args) {    
159         SwingUtilities.invokeLater(new Runnable() {
160             public void run() {
161                 AttendanceFrame demo = new AttendanceFrame();    
162                 demo.setVisible(true);
163             }
164         });
165     }
166 }