1 TestDlg.java 2 package com.synjones.angel; 3 4 import java.awt.*; 5 import java.awt.event.*; 6 import java.io.UnsupportedEncodingException; 7 import java.util.*; 8 9 import javax.swing.*; 10 import javax.swing.table.*; 11 12 import com.sun.jna.win32.*; 13 import com.sun.jna.*; 14 15 public class TestDlg extends JFrame implements ActionListener { 16 private static final long serialVersionUID = -7495940408592595397L; 17 18 private JPanel mainPanel; //主面板 19 private Button[] button = new Button[6]; //主面板上按钮 20 private JPanel[] buttonPanel = new JPanel[4]; //四个二级面板 21 private JPanel[] firstPanel = new JPanel[9]; //第一个二级面板下的九个三级面板 22 private Button[][] b = new Button[4][3]; //二级面板下的12个按钮 23 private Button b33 = new Button("姓名_身份证号");//最后一个二级面板多出的按钮 24 //第一个二级面板内的3个标签和3个编辑框 25 private JLabel lbPort; 26 private JLabel lbMaxByte; 27 private JLabel lbBaud; 28 private JTextField port; 29 private JTextField maxByte; 30 private JTextField baud; 31 32 private JTable table; //信息列表 33 private Table_Model model = null; 34 private JScrollPane s_pan = null; 35 36 public TestDlg() { 37 //设置框架初始化参数 38 this.setTitle("二代证读取"); 39 this.setLocation(200, 50); 40 41 /*初始化工作开始*/ 42 mainPanel = new JPanel(); //初始化主面板 43 //初始化主面板按钮 44 button[0] = new Button("复位SAM(慎用)"); 45 button[1] = new Button("获得SAM状态"); 46 button[2] = new Button("获得SAM序列号"); 47 button[3] = new Button("使用结构体返回信息"); 48 button[4] = new Button("清除所有信息"); 49 button[4].setPreferredSize(new Dimension(100,25)); 50 button[5] = new Button("退出"); 51 button[5].setPreferredSize(new Dimension(94, 25)); 52 //初始化二级面板 53 for (int i = 0; i < 4; i++) { 54 buttonPanel[i] = new JPanel(); 55 } 56 //初始化三级面板 57 for (int i = 0; i < 9; i++) { 58 firstPanel[i] = new JPanel(); 59 } 60 //初始化按钮 61 b[0][0] = new Button("自动寻找读卡器"); 62 b[0][1] = new Button("最大通信字节数"); 63 b[0][2] = new Button("设置通信波特率"); 64 b[0][2].setEnabled(false); //按钮初始不可用 65 b[1][0] = new Button("存在C盘根目录"); 66 b[1][1] = new Button("存在当前目录"); 67 b[1][2] = new Button("存在选定路径"); 68 b[2][0] = new Button("存为Bmp格式"); 69 b[2][1] = new Button("存为Jpeg格式"); 70 b[2][2] = new Button("存为Base64格式"); 71 b[3][0] = new Button("tmp"); 72 b[3][1] = new Button("姓名"); 73 b[3][2] = new Button("身份证号"); 74 //初始化标签 75 lbPort = new JLabel("端口号:"); 76 lbMaxByte = new JLabel("<html>设置最大通信<br>字节数(24-255):</html>"); 77 lbMaxByte.setFont(new java.awt.Font("Dialog", 1, 9)); 78 lbBaud = new JLabel("波特率:"); 79 //初始化编辑框 80 port = new JTextField(6); 81 port.setText("1"); //初始值为1 82 maxByte = new JTextField(6); 83 maxByte.setText("80"); //初始值为80 84 baud = new JTextField(6); 85 baud.setEnabled(false); //初始不可用 86 /*初始化工作结束*/ 87 88 //添加按钮监视事件 89 for (int i = 0; i < 4; i++) { 90 for(int j=0; j<3; j++){ 91 b[i][j].addActionListener(this); 92 } 93 } 94 b33.addActionListener(this); 95 for (int i = 0; i < 6; i++){ 96 button[i].addActionListener(this); 97 } 98 99 //将按钮添加到主面板 100 for ( int i = 0; i < 6; i++) { 101 mainPanel.add(button[i]); 102 } 103 104 //设置各二级面板标题 105 buttonPanel[0].setBorder(BorderFactory.createTitledBorder("SAM设置函数")); 106 buttonPanel[1].setBorder(BorderFactory.createTitledBorder("照片存放路径设置")); 107 buttonPanel[2].setBorder(BorderFactory.createTitledBorder("照片保存格式")); 108 buttonPanel[3].setBorder(BorderFactory.createTitledBorder("照片文件名格式")); 109 110 //设置各二级面板大小及行列数 111 buttonPanel[0].setPreferredSize(new Dimension(260,120)); 112 buttonPanel[0].setLayout(new GridLayout(3, 3, 1, 1)); 113 buttonPanel[1].setPreferredSize(new Dimension(120,120)); 114 buttonPanel[1].setLayout(new GridLayout(3, 1, 1, 5)); 115 buttonPanel[2].setPreferredSize(new Dimension(120,120)); 116 buttonPanel[2].setLayout(new GridLayout(3, 1, 1, 5)); 117 buttonPanel[3].setPreferredSize(new Dimension(120,120)); 118 buttonPanel[3].setLayout(new GridLayout(4, 1, 1, 1)); 119 120 //添加相应内容到九个三级面板 121 firstPanel[0].add(lbPort); 122 firstPanel[1].add(port); 123 firstPanel[2].add(b[0][0]); 124 firstPanel[3].add(lbMaxByte); 125 firstPanel[4].add(maxByte); 126 firstPanel[5].add(b[0][1]); 127 firstPanel[6].add(lbBaud); 128 firstPanel[7].add(baud); 129 firstPanel[8].add(b[0][2]); 130 131 //将三级面板添加到第一个二级面板 132 for (int i = 0; i < 9; i++) { 133 buttonPanel[0].add(firstPanel[i]); 134 } 135 136 //将其余按钮加入相应二级面板 137 for (int i = 1; i < 4; i++) { 138 for (int j = 0; j < 3; j++) { 139 buttonPanel[i].add(b[i][j]); 140 } 141 } 142 buttonPanel[3].add(b33); 143 144 //将二级面板添加到主面板 145 for (int i = 0; i < 4; i++) { 146 mainPanel.add(buttonPanel[i]); 147 } 148 149 /*信息列表设置开始*/ 150 //初始化信息列表 151 model = new Table_Model(20); 152 table = new JTable(model); 153 table.setBackground(Color.white); 154 TableColumnModel tcm = table.getColumnModel(); 155 tcm.getColumn(0).setPreferredWidth(50); 156 tcm.getColumn(1).setPreferredWidth(300); 157 158 s_pan = new JScrollPane(table); 159 s_pan.setPreferredSize(new Dimension(640, 300)); 160 /*信息列表设置结束*/ 161 162 //将信息列表加入主面板 163 mainPanel.add(s_pan); 164 165 //将主面板加入框架 166 this.getContentPane().add(mainPanel); 167 this.setResizable(false); 168 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 169 this.setSize(660, 500); 170 this.setVisible(true); 171 } 172 173 //此接口一定要继承StdCallLibrary 否则读卡错误! 174 public interface SynIDCardAPI extends StdCallLibrary { 175 String path = TestDlg.class.getResource("/").getPath().substring(1).replace("/", "\\") + "SynIDCardAPI"; 176 SynIDCardAPI INSTANCE = (SynIDCardAPI)Native.loadLibrary(path, SynIDCardAPI.class); 177 178 //SAM端口函数 179 public int Syn_SetMaxRFByte(int iPort, char ucByte, int bIfOpen); 180 public int Syn_GetCOMBaudEx(int iPort); 181 public int Syn_SetCOMBaud(int iPort, int uiCurrBaud, int uiSetBaud); 182 public int Syn_OpenPort(int iPort); 183 public int Syn_ClosePort (int iPort); 184 //SAM类函数 185 public int Syn_ResetSAM(int iPort, int iIfOpen); 186 public int Syn_GetSAMStatus(int iPort, int iIfOpen); 187 public int Syn_GetSAMID(int iPort, char[] pucSAMID, int iIfOpen); 188 //身份证卡类函数 189 public int Syn_StartFindIDCard(int iPort, char[] pucIIN, int iIfOpen); 190 public int Syn_SelectIDCard(int iPort, char[] pucSN, int iIfOpen); 191 public int Syn_ReadMsg(int iPort, int iIfOpen, IDCardData pINCardData); 192 public int Syn_FindReader(); 193 //设置附加功能函数 194 public int Syn_SetPhotoPath(int iOption, String cPhotopath); 195 public int Syn_SetPhotoType(int iType); 196 public int Syn_SetPhotoName(int iType); 197 public int Syn_SetSexType( int iType ); 198 public int Syn_SetNationType(int iType); 199 public int Syn_SetBornType(int iType); 200 public int Syn_SetUserLifeBType(int iType); 201 public int Syn_SetUserLifeEType(int iTyp, int iOption); 202 } 203 204 //显示信息自动滚动到最后一行 205 private void scrollEnd(){ 206 int rowCount = table.getRowCount(); 207 Rectangle rect = table.getCellRect(rowCount-1, 0, true); 208 table.scrollRectToVisible(rect); 209 } 210 211 //继承自ActionListener 212 public void actionPerformed(ActionEvent e) { 213 Object source = e.getSource(); 214 if (source == button[0]) { 215 String sMsg; 216 int iPort = Integer.parseInt(port.getText()); 217 int nRet = SynIDCardAPI.INSTANCE.Syn_OpenPort(iPort); 218 if (nRet == 0) 219 { 220 nRet = SynIDCardAPI.INSTANCE.Syn_ResetSAM(iPort, 0); 221 if (nRet == 0) 222 { 223 sMsg = "复位SAM模块成功"; 224 } 225 else 226 { 227 sMsg = "复位SAM模块失败"; 228 } 229 } 230 else 231 { 232 sMsg = "打开端口错误"; 233 } 234 SynIDCardAPI.INSTANCE.Syn_ClosePort(iPort); 235 model.addRow(sMsg); 236 table.updateUI(); 237 scrollEnd(); 238 } 239 else if (source == button[1]) { 240 String sMsg; 241 int iPort = Integer.parseInt(port.getText()); 242 int nRet = SynIDCardAPI.INSTANCE.Syn_OpenPort(iPort); 243 if (nRet == 0) 244 { 245 nRet = SynIDCardAPI.INSTANCE.Syn_GetSAMStatus(iPort, 0); 246 if (nRet == 0) 247 { 248 sMsg = "SAM模块状态正常"; 249 } 250 else 251 { 252 sMsg = "获得SAM模块状态失败"; 253 } 254 } 255 else 256 { 257 sMsg = "打开端口错误"; 258 } 259 SynIDCardAPI.INSTANCE.Syn_ClosePort(iPort); 260 model.addRow(sMsg); 261 table.updateUI(); 262 scrollEnd(); 263 } 264 else if (source == button[2]) { 265 String sMsg; 266 int iPort = Integer.parseInt(port.getText()); 267 int nRet = SynIDCardAPI.INSTANCE.Syn_OpenPort(iPort); 268 if (nRet == 0) 269 { 270 char[] strSAMID = new char[8]; 271 nRet = SynIDCardAPI.INSTANCE.Syn_GetSAMID(iPort, strSAMID, 0); 272 if (nRet == 0) 273 { 274 long[] iSAMID = new long[3]; 275 iSAMID[0] = (long)strSAMID[3] * 65536 + (long)strSAMID[2]; 276 iSAMID[1] = (long)strSAMID[5] * 65536 + (long)strSAMID[4]; 277 iSAMID[2] = (long)strSAMID[7] * 65536 + (long)strSAMID[6]; 278 sMsg = String.format("按16字节获得SAM模块ID成功,SAM模块ID为: %d-%d-%d-%d-%d", (int)strSAMID[0], (int)strSAMID[1], iSAMID[0], iSAMID[1], iSAMID[2]); 279 } 280 else 281 { 282 sMsg = "读取SAM ID号错误"; 283 } 284 } 285 else 286 { 287 sMsg = "打开端口错误"; 288 } 289 SynIDCardAPI.INSTANCE.Syn_ClosePort(iPort); 290 model.addRow(sMsg); 291 table.updateUI(); 292 scrollEnd(); 293 } 294 else if (source == button[3]) { 295 String sMsg; 296 SynIDCardAPI.INSTANCE.Syn_SetSexType(1); 297 SynIDCardAPI.INSTANCE.Syn_SetNationType(1); 298 SynIDCardAPI.INSTANCE.Syn_SetBornType(2); 299 SynIDCardAPI.INSTANCE.Syn_SetUserLifeBType(3); 300 SynIDCardAPI.INSTANCE.Syn_SetUserLifeEType(4,1); 301 302 int iPort = Integer.parseInt(port.getText()); 303 int nRet = SynIDCardAPI.INSTANCE.Syn_OpenPort(iPort); 304 if (nRet == 0) 305 { 306 if (SynIDCardAPI.INSTANCE.Syn_SetMaxRFByte(iPort, (char)80, 0) == 0) 307 { 308 char[] pucIIN = new char[8]; 309 char[] pucSN = new char[8]; 310 IDCardData idcardData = new IDCardData(); 311 nRet = SynIDCardAPI.INSTANCE.Syn_StartFindIDCard(iPort, pucIIN, 0); 312 nRet = SynIDCardAPI.INSTANCE.Syn_SelectIDCard(iPort, pucSN, 0); 313 if (SynIDCardAPI.INSTANCE.Syn_ReadMsg(iPort, 0, idcardData) == 0) 314 { 315 sMsg= "读取身份证信息成功!"; 316 model.addRow(sMsg); 317 table.updateUI(); 318 try{ 319 String strTemp = new String(idcardData.Name, "GBK"); 320 sMsg = String.format("姓名:%s", strTemp); 321 model.addRow(sMsg); 322 table.updateUI(); 323 strTemp = new String(idcardData.Sex, "GBK"); 324 sMsg = String.format("性别:%s", strTemp); 325 model.addRow(sMsg); 326 table.updateUI(); 327 strTemp = new String(idcardData.Nation, "GBK"); 328 sMsg = String.format("民族:%s", strTemp); 329 model.addRow(sMsg); 330 table.updateUI(); 331 strTemp = new String(idcardData.Born, "GBK"); 332 sMsg = String.format("出生:%s", strTemp); 333 model.addRow(sMsg); 334 table.updateUI(); 335 strTemp = new String(idcardData.Address, "GBK"); 336 sMsg = String.format("住址:%s", strTemp); 337 model.addRow(sMsg); 338 table.updateUI(); 339 strTemp = new String(idcardData.IDCardNo, "GBK"); 340 sMsg = String.format("身份证号:%s", strTemp); 341 model.addRow(sMsg); 342 table.updateUI(); 343 strTemp = new String(idcardData.GrantDept, "GBK"); 344 sMsg = String.format("发证机关:%s", strTemp); 345 model.addRow(sMsg); 346 table.updateUI(); 347 strTemp = new String(idcardData.UserLifeBegin, "GBK"); 348 sMsg = String.format("有效期开始:%s", strTemp); 349 model.addRow(sMsg); 350 table.updateUI(); 351 strTemp = new String(idcardData.UserLifeEnd, "GBK"); 352 sMsg = String.format("有效期结束:%s", strTemp); 353 model.addRow(sMsg); 354 table.updateUI(); 355 strTemp = new String(idcardData.PhotoFileName, "GBK"); 356 sMsg = String.format("照片:%s", strTemp); 357 model.addRow(sMsg); 358 table.updateUI(); 359 }catch (UnsupportedEncodingException une) { 360 une.printStackTrace(); 361 } 362 } 363 else 364 { 365 sMsg = "读取身份证信息错误!"; 366 model.addRow(sMsg); 367 table.updateUI(); 368 } 369 } 370 } 371 else 372 { 373 sMsg = "打开端口错误"; 374 model.addRow(sMsg); 375 table.updateUI(); 376 } 377 SynIDCardAPI.INSTANCE.Syn_ClosePort(iPort); 378 scrollEnd(); 379 } 380 else if (source == button[4]) { 381 model.removeRows(0, model.getRowCount()); 382 table.updateUI(); 383 } 384 else if (source == button[5]) { 385 System.exit(0); 386 } 387 else if(source == b[0][0]) { 388 int nRet; 389 String sMsg, sMsg2; 390 nRet = SynIDCardAPI.INSTANCE.Syn_FindReader(); 391 if (nRet == 0) 392 { 393 sMsg = "没有找打读卡器"; 394 } 395 else 396 { 397 //Toolkit.getDefaultToolkit().beep(); 398 baud.setEnabled(true); 399 b[0][2].setEnabled(true); 400 if (nRet >1000) 401 { 402 sMsg = String.format("读卡器连接在USB端口 %d", nRet); 403 } 404 else 405 { 406 try{ 407 Thread.sleep(200); 408 }catch (InterruptedException exc) { 409 System.out.println("error"); 410 } 411 int uiCurrBaud = SynIDCardAPI.INSTANCE.Syn_GetCOMBaudEx(nRet); 412 sMsg2 = String.format("%d", uiCurrBaud); 413 baud.setText(sMsg2); 414 sMsg = String.format("读卡器连接在串口 %d,当前SAM波特率为 %d", nRet, uiCurrBaud); 415 } 416 sMsg2 = String.format("%d", nRet); 417 port.setText(sMsg2); 418 } 419 model.addRow(sMsg); 420 table.updateUI(); 421 scrollEnd(); 422 } 423 else if (source == b[0][1]) { 424 String sMsg,sMsg2; 425 sMsg2 = port.getText(); 426 int iPort = Integer.parseInt(sMsg2); 427 sMsg2 = maxByte.getText(); 428 int iByte = Integer.parseInt(sMsg2); 429 char iMaxByte = (char)iByte; 430 int nRet = SynIDCardAPI.INSTANCE.Syn_OpenPort(iPort); 431 if (nRet == 0) 432 { 433 if (SynIDCardAPI.INSTANCE.Syn_GetSAMStatus(iPort, 0) == 0) 434 { 435 if(SynIDCardAPI.INSTANCE.Syn_SetMaxRFByte(iPort, iMaxByte, 0) == 0) 436 { 437 sMsg = String.format("设置最大通讯字节数成功,最大通讯字节数为 %d", iByte); 438 } 439 else 440 { 441 sMsg = "设置最大通讯字节数出错!"; 442 } 443 } 444 else 445 { 446 sMsg = String.format("端口 %d 上没有连接读卡器!", iPort); 447 } 448 } 449 else 450 { 451 sMsg = "打开端口错误!"; 452 } 453 SynIDCardAPI.INSTANCE.Syn_ClosePort(iPort); 454 model.addRow(sMsg); 455 table.updateUI(); 456 scrollEnd(); 457 } 458 else if (source == b[0][2]) { 459 String sMsg,sMsg2; 460 sMsg2 = port.getText(); 461 int iPort = Integer.parseInt(sMsg2); 462 int iCurrBaud = SynIDCardAPI.INSTANCE.Syn_GetCOMBaudEx(iPort); 463 if (iCurrBaud == 0 ) 464 { 465 sMsg="获得当前读卡器波特率失败"; 466 model.addRow(sMsg); 467 table.updateUI(); 468 return; 469 } 470 sMsg2 = baud.getText(); 471 int iSetBaud = Integer.parseInt(sMsg2); 472 SynIDCardAPI.INSTANCE.Syn_ClosePort(iPort); 473 if(SynIDCardAPI.INSTANCE.Syn_SetCOMBaud(iPort, iCurrBaud, iSetBaud) == 0) 474 { 475 sMsg = String.format("设置读卡器波特率成功,当前波特率为 %d ", iSetBaud); 476 } 477 else 478 { 479 sMsg = "设置读卡器波特率失败"; 480 } 481 model.addRow(sMsg); 482 table.updateUI(); 483 scrollEnd(); 484 } 485 else if (source == b[1][0]) { 486 String strTmp = new String(); 487 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoPath(0, strTmp); 488 String strInfo = new String(); 489 strInfo = String.format("照片存放路径设置为 C:,nRet = %d", nRet); 490 model.addRow(strInfo); 491 table.updateUI(); 492 scrollEnd(); 493 } 494 else if (source == b[1][1]) { 495 String strTmp = new String(); 496 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoPath(1, strTmp); 497 String strInfo = new String(); 498 if (nRet == 0) 499 strInfo = String.format("照片存放路径设置为当前路径,nRet = %d", nRet); 500 else 501 strInfo = String.format("照片存放路径设置错误,nRet = %d", nRet); 502 model.addRow(strInfo); 503 table.updateUI(); 504 scrollEnd(); 505 } 506 else if (source == b[1][2]){ 507 String strInfo = new String(); 508 JFileChooser fileChooser = new JFileChooser("."); 509 fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 510 fileChooser.setDialogTitle("打开文件夹"); 511 int ret = fileChooser.showOpenDialog(null); 512 if (ret == JFileChooser.APPROVE_OPTION) { 513 //文件夹路径 514 String strPath = fileChooser.getSelectedFile().getAbsolutePath(); 515 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoPath(0, strPath); 516 strInfo = String.format("照片存放路径设置为 %s,nRet = %d", strPath, nRet); 517 } 518 else { 519 strInfo = "选取路径失败!"; 520 } 521 model.addRow(strInfo); 522 table.updateUI(); 523 scrollEnd(); 524 } 525 else if (source == b[2][0]) { 526 String sMsg = new String(); 527 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoType(0); 528 if (nRet == 0) 529 { 530 sMsg = String.format("照片保存格式设置为 Bmp,nRet = %d", nRet); 531 } 532 else 533 { 534 sMsg = String.format("照片保存格式设置失败,nRet = %d", nRet); 535 } 536 model.addRow(sMsg); 537 table.updateUI(); 538 scrollEnd(); 539 } 540 else if (source == b[2][1]) { 541 String sMsg = new String(); 542 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoType(1); 543 if (nRet == 0) 544 { 545 sMsg = String.format("照片保存格式设置为 Jpeg,nRet = %d", nRet); 546 } 547 else 548 { 549 sMsg = String.format("照片保存格式设置失败,nRet = %d", nRet); 550 } 551 model.addRow(sMsg); 552 table.updateUI(); 553 scrollEnd(); 554 } 555 else if (source == b[2][2]) { 556 String sMsg = new String(); 557 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoType(2); 558 if (nRet == 0) 559 { 560 sMsg = String.format("照片保存格式设置为 Base64,nRet = %d", nRet); 561 } 562 else 563 { 564 sMsg = String.format("照片保存格式设置失败,nRet = %d", nRet); 565 } 566 model.addRow(sMsg); 567 table.updateUI(); 568 scrollEnd(); 569 } 570 else if (source == b[3][0]) { 571 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoName(0); 572 String sMsg; 573 if (nRet == 0) 574 { 575 sMsg = String.format("照片保存文件名格式设置为 tmp,nRet = %d", nRet); 576 } 577 else 578 { 579 sMsg = String.format("照片保存文件名格式设置失败,nRet = %d", nRet); 580 } 581 model.addRow(sMsg); 582 table.updateUI(); 583 scrollEnd(); 584 } 585 else if (source == b[3][1]) { 586 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoName(1); 587 String sMsg; 588 if (nRet == 0) 589 { 590 sMsg = String.format("照片保存文件名格式设置为 姓名,nRet = %d", nRet); 591 } 592 else 593 { 594 sMsg = String.format("照片保存文件名格式设置失败,nRet = %d", nRet); 595 } 596 model.addRow(sMsg); 597 table.updateUI(); 598 scrollEnd(); 599 } 600 else if (source == b[3][2]) { 601 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoName(2); 602 String sMsg; 603 if (nRet == 0) 604 { 605 sMsg = String.format("照片保存文件名格式设置为 身份证号,nRet = %d", nRet); 606 } 607 else 608 { 609 sMsg = String.format("照片保存文件名格式设置失败,nRet = %d", nRet); 610 } 611 model.addRow(sMsg); 612 table.updateUI(); 613 scrollEnd(); 614 } 615 else if (source == b33) { 616 int nRet = SynIDCardAPI.INSTANCE.Syn_SetPhotoName(3); 617 String sMsg; 618 if (nRet == 0) 619 { 620 sMsg = String.format("照片保存文件名格式设置为 姓名_身份证号,nRet = %d", nRet); 621 } 622 else 623 { 624 sMsg = String.format("照片保存文件名格式设置失败,nRet = %d", nRet); 625 } 626 model.addRow(sMsg); 627 table.updateUI(); 628 scrollEnd(); 629 } 630 } 631 632 public static void main(String[] args) { 633 new TestDlg(); 634 } 635 } 636 637 class Table_Model extends AbstractTableModel { 638 private static final long serialVersionUID = -7495940408592595395L; 639 private Vector content = null; 640 private String[] title_name = {"发生时间", "信息"}; 641 642 public Table_Model(int count) { 643 content = new Vector(count); 644 } 645 646 //添加数据 647 public void addRow(String strInfo) { 648 Vector v = new Vector(2); 649 Calendar now = Calendar.getInstance(); 650 String time = now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH)+1)+"-"+now.get(Calendar.DAY_OF_MONTH) 651 +" "+now.get(Calendar.HOUR_OF_DAY)+":"+now.get(Calendar.MINUTE)+":"+now.get(Calendar.SECOND); 652 v.add(0, time); 653 v.add(1, strInfo); 654 content.add(v); 655 } 656 657 //删除数据 658 public void removeRows(int row, int count) { 659 for (int i = 0; i < count; i++) { 660 if (content.size() > row) { 661 content.remove(row); 662 } 663 } 664 } 665 666 //以下函数为继承自AbstractTableModel 667 public String getColumnName(int col) { 668 return title_name[col]; 669 } 670 public int getColumnCount() { 671 return title_name.length; 672 } 673 public int getRowCount() { 674 return content.size(); 675 } 676 public Object getValueAt(int row, int col) { 677 return ((Vector) content.get(row)).get(col); 678 } 679 } 680 681 682 IDCardData.java 683 package com.synjones.angel; 684 685 import com.sun.jna.Structure; 686 687 public class IDCardData extends Structure { 688 public byte[] Name; //注意,不能是char[] name;否则会乱码!转都转不了! 689 public byte[] Sex; 690 public byte[] Nation; 691 public byte[] Born; 692 public byte[] Address; 693 public byte[] IDCardNo; 694 public byte[] GrantDept; 695 public byte[] UserLifeBegin; 696 public byte[] UserLifeEnd; 697 public byte[] reserved; 698 public byte[] PhotoFileName; 699 700 public IDCardData(){ 701 Name=new byte[32]; 702 Sex=new byte[6]; 703 Nation=new byte[20]; 704 Born=new byte[18]; 705 Address=new byte[72]; 706 IDCardNo=new byte[38]; 707 GrantDept=new byte[32]; 708 UserLifeBegin=new byte[18]; 709 UserLifeEnd=new byte[18]; 710 reserved=new byte[38]; 711 PhotoFileName=new byte[255]; 712 } 713 }
大概看了一下代码,这个用JAVA写的界面,其中还用到了身份证读卡器,
BS结构(浏览器)要想使用硬件(如读卡器),我觉得需要使用activex,把DLL写成activex
自己封装的读卡器代码?
没有具体作过这个东西,大致应该是这样!
dll文件直接调用用可以不可以,只是读取一下信息然后保存到数据中,其他的不管
直接点就是怎么把button[3]这个时间用写好的action改一下,然后前台jsp页面调用一下,显示出来,保存
不好意思,我不会你说的这种实现方式, JAVA awt 和JAVA WEB开发能一起使用吗?
@韩之一: 不能啊,得需要改把awt定义的按钮全部改成jsp传输的属性值,后台action再获取进行操作
你是想前台用awt,后台用JSP吗?
@韩之一: 前台jsp,后台action,Struts2,的,
@ibabe: 你能帮我看看吗,加qq1261074978
首先你要先知道在web开发下,你怎么调用读卡器
看一下,你使用的读卡器是否提供了web用的activex或cab包
http://www.java123.net/v/432761.html
@韩之一: 真的很感谢你,我看不懂我现在就想问一下在jsp页面上写了一个<input type="button" value="使用结构体读取信息" id="ReadCardAutoBtn" name="ReadCardAutoBtn" onclick="sub('<%=basePath%>Idcarread/IdcarreadAction')">
想点击这个按钮后调用IdcarreadAction该怎么弄
写个servlet封装后,调用action,前台按钮调用servlet,执行action,获取到身份证信息,保存之
这个有点麻烦,因为activeX(OCX控件)由于浏览器的安全模型,并不能直接访问客户机的资源,需要做activex的签名,好像是这样,10多年前玩过这个。
吐糟一下,你们老板瞎胡闹,为啥要用BS啊,这个明显不适合啊。
呵呵,就是瞎闹的,看看我的水平