JAVA call Control Development

HomoloCzh have recently received a small partner, said demand is to have a write c # scanning, access to other functions winfrom image control is embedded in java Swing them, so that small partners very upset ah, and has been studied from the year ago period using a variety of methods.

jcob, comfyj, jawin, jni, jna so many ways. (Either directly dll calls a method, called indirectly with some C a shell package, and then use java call, or even have come direct calls coming exe) clearly talk winfrom current demand is fitted into stepped swing which involves

Between procedure calls and embedded development, so it is quite difficult. Small Internet to find partners for a long time, did not find the information for reference. The last to give up.

I do also out of curiosity, although most of them are now doing java focus on back-office services. Performance server architecture of control CS rarely do with java SWING, but because of a small partner chat knew this thing, then go online looked really very few similar requirements post, almost no one done it before is not currently recommended do not know the future will not, because from then 1.4 java jdk not been updated swing piece, and this piece of founding the Web. But it happens in the degree of your mother and chat, I found a post that is java SWT word document can be displayed, and then I thought there should be a door try holding the attitude, did not think really successful ha ha. We did not talk much and paste the code process

Principle: The SWT display video box control, and then on the swing SWT interface, interactive call and then implemented by SWT dll method calls package
premise: use of OCX or dll must be registered in the system registry, installation control installation or by a command packet regsvr32 xxxx.dll

The JVM 1. First digit (32-bit or 64-bit) org.eclipse.swt.xxx.jar introduced which corresponds to the project to see if the number of bits of the JVM does not know Baidu on their own, there are many ways of

 There is one kind cmd teach you to execute java -version

 

 

 2. To call the ocx environment variables into the system directory, or jdk bin directory, or load your own

 

 

Here 2.1 is the interface implementation class code

*
* Procedure:
* Face acquisition control installation 1.
* 2. Verify or install dll ocx regsvr32 xxx.ocx already registered in the registry 32 or xxx.dll is the regsvr
* 3. run the software, 64, 32, or confirm JVM32 Please load position org.eclipse.swt.x86.jar, 64-bit load the org.eclipse.swt.x64.jar
* 4. 64 64 JDK dynamic load library, JDK load 32-bit 32-bit dynamic link library
* 5. direct executes the main function of the operating face acquisition program
*
* @author HOMOLOCzh
* @date 20.20022 million
* /
public class JavaSwingDoFaceWinfrom the extends the JFrame {

Private Long static Final serialVersionUID = 1L;

Private the JPanel jPanelLogo;
Private the JPanel jPanelBtn;
Private the JPanel jPanelCapture;
Private the JButton jButtonCheck;
Private jButtonOpenDev JButton;
Private JButton jButtonCloseDev;
Private JButton jButtonAutoCap;
private JButton jButtonManualCap;
private JTextArea jTextAreaParam;
private JTextArea jTextAreaResult;
private JScrollPane jscrollPaneParam;
private JScrollPane jscrollPaneResult;
private JLabel jLabelImg;

private static JavadoOcx controlL = null;
private static JavadoOcx controlR = null;

public JavaSwingDoFaceWinfrom()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
if(controlL != null)
{
controlL.closeDevice();
}
}
});
}

/ **
* acquisition control face SWT graphical control
* /
Private = new new static swtCanvas the Canvas the Canvas () {
Private Long Final static serialVersionUID = 1L;

@Override
public void o addNotify () {
super.addNotify ();
the synchronized (getTreeLock ()) {
// start a new thread to avoid blocking the
new new the Thread () {
public void RUN () {

String tesoClsid = AppConfig.getConfig (AppConfig.TESO_PROGID );
// initialize SWT
Display Display the display = new new ();
Shell _shell = SWT_AWT.new_Shell (the display, swtCanvas);
_shell.setLayout (new new org.eclipse.swt.layout.RowLayout ());
// first loading a window ocx
OleFrame _frameL = new new OleFrame (_shell, SWT.NONE);
// TesoSeeu.CmbcSee: registered in the registry controls PROGID, is the name
OleControlSite _siteL = new new OleControlSite (_frameL, SWT.NONE, tesoClsid);
_siteL .doVerb (OLE.OLEIVERB_SHOW);
_siteL.setSize (400, 300);

// load a second window ocx
OleFrame _frameR = new OleFrame(_shell, SWT.NONE);
OleControlSite _siteR = new OleControlSite(_frameR, SWT.NONE, tesoClsid);
_siteR.doVerb(OLE.OLEIVERB_SHOW);
_siteR.setSize(400, 300);

OleAutomation _autoL = new OleAutomation(_siteL);
controlL = new JavadoOcx(_autoL);
OleAutomation _autoR = new OleAutomation(_siteR);
controlR = new JavadoOcx(_autoR);

swtCanvas.setSize(820, 300);

_shell.pack();
while (!_shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}.start();
}
}
};

private void doAble(boolean flag)
{
jButtonCheck.setEnabled(flag);
jButtonOpenDev.setEnabled(flag);
jButtonCloseDev.setEnabled(flag);
jButtonAutoCap.setEnabled(flag);
jButtonManualCap.setEnabled(flag);

}

private void initGUI() {
try {
{
this.setIconImage(new ImageIcon(getClass().getClassLoader().getResource("images/teso_logo.png")).getImage());
setLayout(null);
{
jPanelLogo = new JPanel();
jPanelLogo.setBounds(0, 0, 800, 52);
jPanelLogo.setBackground(new java.awt.Color(255, 255, 200));
jPanelLogo.setLayout(new BorderLayout());
jLabelImg = new JLabel(new ImageIcon(getClass().getClassLoader().getResource("images/techshino.png"))) ;
jPanelLogo.add(jLabelImg, BorderLayout.WEST);
getContentPane().add(jPanelLogo);
}

{
jPanelBtn = new JPanel();
jPanelBtn.setBounds(0, 500, 800, 50);
jPanelBtn.setLayout(new GridLayout(1, 5));
getContentPane().add(jPanelBtn);
}

{
jPanelCapture = new JPanel();
jPanelCapture.setLayout(new GridLayout());
jPanelCapture.setBounds(0, 50, 800, 300);
jPanelCapture.add(swtCanvas);
getContentPane().add(jPanelCapture);
}

{
jTextAreaParam = new JTextArea(TesoFaceConstant.getParam(), 10, 15);
jTextAreaParam.setLineWrap(true);
jPanelBtn.add(jTextAreaParam);

jscrollPaneParam = new JScrollPane(jTextAreaParam);
jscrollPaneParam.setBounds(0, 350, 400, 150);
getContentPane().add(jscrollPaneParam);

}
{
jTextAreaResult = new JTextArea(10, 15);
jTextAreaResult.setLineWrap(true);
jPanelBtn.add(jTextAreaResult);

jscrollPaneResult = new JScrollPane(jTextAreaResult);
jscrollPaneResult.setBounds(400, 350, 400, 150);
getContentPane().add(jscrollPaneResult);
}

{
jButtonCheck = new JButton();
jPanelBtn.add(jButtonCheck);
jButtonCheck.setText("检测摄像头状态");
jButtonCheck.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doAble(false);
// 线程打开摄像头,防止卡死
new Thread() {
public void run() {
jTextAreaResult.setText("");
String retXml = controlL.checkDevice(jTextAreaParam.getText());
jTextAreaResult.setText(retXml);
doAble(true);
}
}.start();
}
});
}
{
jButtonOpenDev = new JButton();
jPanelBtn.add(jButtonOpenDev);
jButtonOpenDev.setText("打开摄像头");
jButtonOpenDev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doAble(false);
// 线程打开摄像头,防止卡死
new Thread() {
public void run() {
jTextAreaResult.setText("");
String retXml = controlL.openDevice(jTextAreaParam.getText());
jTextAreaResult.setText(retXml);
doAble(true);
}
}.start();


}
});
}

{
jButtonCloseDev = new JButton();
jPanelBtn.add (jButtonCloseDev);
jButtonCloseDev.setText ( "Close camera");

jButtonCloseDev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextAreaResult.setText("");
String retXml = controlL.closeDevice();
jTextAreaResult.setText(retXml);
}
});
}

{
jButtonManualCap = new JButton();
jPanelBtn.add(jButtonManualCap);
jButtonManualCap.setText("手动抓拍人脸");

jButtonManualCap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextAreaResult.setText("");
String retXml = controlL.captureFaceManual(jTextAreaParam.getText(), "123456789012345678", "12345678901234567890123456789012");
controlR.showImg("123456789012345678", "12345678901234567890123456789012", retXml);
jTextAreaResult.setText(retXml);
}
});
}

{
JButtonAutoCap the JButton new new = ();
jPanelBtn.add (jButtonAutoCap);
jButtonAutoCap.setText ( "automatically capture face");

jButtonAutoCap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doAble(false);
// 线程打开摄像头,防止卡死
new Thread() {
public void run() {
jTextAreaResult.setText("");
String retXml = controlL.captureFaceAuto(jTextAreaParam.getText(), "123456789012345678", "12345678901234567890123456789012");
controlR.showImg("123456789012345678", "12345678901234567890123456789012", retXml);
jTextAreaResult.setText(retXml);
doAble(true);
}
}.start();
}
});
}
}

this.setSize(806, 580);
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
JavaSwingDoFaceWinfrom frame = new JavaSwingDoFaceWinfrom();
frame.initGUI();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setResizable(false);
}
}

 

2.2 The following is a method of implementation is to call for information purposes only ocx

package javaDoWinform;


import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.Variant;

public class JavadoOcx{

private OleAutomation oleAutomation;

public JavadoOcx(OleAutomation oleAutomation)
{
this.oleAutomation = oleAutomation;
}

/**
* 获取ole中的参数编号
* @param name 参数名
* @return 参数序号
*/
private int getID(String name) {
try {
int[] ids = oleAutomation.getIDsOfNames(new String[] { name });
if(ids == null)
{
return -1;
}
if (ids.length >= 0)
return ids[0];
} catch (RuntimeException e) {
e.printStackTrace();
}
return -1;
}

/ **
* performing a method without parameters
* @param methodName method name
* @return result set
* /
Private Execute the Variant (String methodName) {
return Execute (methodName, null);
}

/ **
* performing the method with arguments
* @param methodName method name
* @param args parameter set
* @return result set
* /
Private Execute the Variant (String methodName, the Variant [] args) {
int the getID MID = (methodName);
IF (MID <0) {
return null;
}
the Variant rtnv = null;
IF (args == null) {
rtnv = oleAutomation.invoke (MID);
} the else {
rtnv = oleAutomation.invoke (MID, args);
}
return rtnv;
}

/ **
* state detecting camera
* @param devParam face acquisition control parameter XML
* results @return detection apparatus, XML
* /
public String checkDevice (String devParam)
{
the Variant var [] = new new the Variant [. 1];
var[0] = new Variant(devParam);
return execute(TesoFaceConstant.TESO_CHECKDEVICE, var).getString();

}

/ **
* open the camera
* @param devParam face acquisition control parameter XML
* @return result apparatus open, XML
* /
public String openDevice (String devParam) {
the Variant var [] = new new the Variant [. 1];
var [0 ] = new new the Variant (devParam);
return Execute (TesoFaceConstant.TESO_OPENDEVICE, var) .getString ();
}

/ **
* Close the camera
* @return Close apparatus, XML
* /
public String closeDevice () {
return Execute (TesoFaceConstant.TESO_CLOSEDEVICE) .getString ();
}

/ **
* on the display image control
* @param cardNo identity No.
* @param the serialNo serial
captureFaceAuto retXml collected or returned captureFaceManual * @param of XML
* @return result image displayed, XML
* /
public String ShowImg (String cardNo, the serialNo String, String retXml)
{
the Variant var [] = the Variant new new [. 3];
var [0] = new new the Variant (cardNo);
var [. 1] = new new the Variant (the serialNo);
var [2] = new new the Variant (retXml);
return Execute (TesoFaceConstant.TESO_SHOWIMGA, var) .getString ();
}

/ **
* Automatically capture the human face
* @param devParam face acquisition parameters, xml
* @param cardNo ID number
* @param serialNo serial number
* @return automatically capture results, xml
* /
public String captureFaceAuto (String devParam, cardNo String, String the serialNo)
{
the Variant var [] = new new the Variant [. 3];
var [0] = new new the Variant (devParam);
var [. 1] = new new the Variant (cardNo);
var [2] = new new the Variant (the serialNo);
the Variant RET = Execute (TesoFaceConstant.TESO_GETFACEB64A, var);
IF (RET == null)
{
return "";
}
return ret.getString ();
}

/ **
* manual capture facial
* @param devParam face acquisition parameters, XML
* @ param cardNo ID number
* @param serialNo serial number
* @return 手动抓拍的结果,xml
*/
public String captureFaceManual(String devParam, String cardNo, String serialNo)
{
Variant var[] = new Variant[3];
var[0] = new Variant(devParam);
var[1] = new Variant(cardNo);
var[2] = new Variant(serialNo);
Variant ret = execute(TesoFaceConstant.TESO_GETFACEB64B, var);
if(ret == null)
{
return "";
}
return ret.getString();
}

}


5. Due to company secrets, no corresponding OCX upload, you call your own OCX or other controls can be based on ideas, hope forgive me!

 

Guess you like

Origin www.cnblogs.com/homoloCzh/p/12335975.html