各位高手,过来一下,请问如何在delphi调用java写的一个类呢。(50分)

  • 主题发起人 主题发起人 zmxk
  • 开始时间 开始时间
Z

zmxk

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何在delphi调用java写的一个类呢。有例子吗?请email一个给我。谢谢。zmxk@etang.com
 
用COM接口
 
shellexcute or winexcute
 
to arlierever and nc2t
能详细一吗?最好有个例子。
Video_java.class
这个类的源码。我想在delhpi调用他。
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: video_java.java
import java.applet.Applet;
import java.awt.*;
import java.io.*;
import java.net.Socket;
import java.net.URL;
public class video_java extends Applet
implements Runnable
{
private boolean isStandalone;
static int sint = 5;
do
uble rotation;
do
uble fps;
Image mImage1;
Image mImage;
Image offimage;
Image pre_image;
Thread runThread;
public String ip;
int port;
int counter;
int sizecounter;
int w;
int h;
Thread clockThread;
PrintWriter pw;
Socket sock;
InputStream is;
int mark;
byte byte_image[];
int testbyte;
int before_width;
int before_height;
int j1;
int j2;
Dimension d;
boolean running;
long t0;
long t1;
long elapsetime;
long t2;
int frames;
int empty;
int display_type;
int size_flag;
int fresh_flag;
int frames1;
int start;
int length;
int len0;
BufferedReader br;
Graphics offG;
MediaTracker imageTracker;
private Graphics gContext;
private Image buffer;
Image Buffer;
Graphics gBuffer;
String s1;
String s2;
String s3;
String s4;
public String getParameter(String s, String s5)
{
if(isStandalone)
return System.getProperty(s, s5);
if(getParameter(s) != null)
return getParameter(s);
else
return s5;
}
public video_java()
{
isStandalone = false;
running = true;
empty = 1;
display_type = 1;
length = sizecounter;
s1 = "";
s2 = "";
s3 = "";
s4 = "";
}
public void init()
{
System.out.println("test1");
showStatus("Init...");
setBackground(SystemColor.controlLtHighlight);
d = getSize();
offimage = createImage(640, 480);
offG = offimage.getGraphics();
offG.setColor(Color.white);
offG.fillRect(0, 0, 640, 640);
URL url = getCodeBase();
String s = url.toString();
int i = 0;
for(int j = 8;
j < s.length();
j++)
{
if(s.charAt(j) != '/' &amp;&amp;
s.charAt(j) != ':')
continue;
i = j;
break;
}
ip = String.valueOf(s.substring(7, i));
if(getParameter("PORT") != null)
{
String s5 = getParameter("PORT");
port = Integer.parseInt(s5);
} else
{
System.out.println("Cannot get port ... use the default 2222 ");
port = 2222;
}
buffer = createImage(640, 640);
gContext = buffer.getGraphics();
gContext.setColor(Color.blue);
gContext.fillRect(0, 0, 640, 640);
try
{
jbInit();
}
catch(Exception exception)
{
exception.printStackTrace();
}
clockThread = new Thread(this);
clockThread.start();
}
public void run()
{
do
{
mark = 0;
try
{
sock = new Socket(ip, port);
}
catch(Throwable _ex)
{
Container container;
for(container = getParent();
!(container instanceof Frame);
container = container.getParent());
Frame frame = (Frame)container;
YesDialog yesdialog = new YesDialog(frame, "Video connection to camera failed.Please try again.");
yesdialog.show();
try
{
Thread.sleep(2000L);
}
catch(Exception _ex2)
{
System.out.println("connection failed");
}
mark = 1;
}
} while(mark != 0);
while(running)
{
mark = 0;
if(frames == 0)
t0 = System.currentTimeMillis();
getdata();
System.gc();
}
}
private void jbInit()
throws Exception
{
setBackground(SystemColor.controlLtHighlight);
setLayout(null);
}
public String getAppletInfo()
{
return "Applet Information";
}
public String[][] getParameterInfo()
{
return null;
}
public void paint(Graphics g, Image image)
{
super.paint(g);
if(empty != 2)
showStatus("number of users: " + j1);
else
if(empty == 2)
showStatus("number of users: " + j1 + " , fps(frames per second): " + (long)fps);
if(fresh_flag == 1)
{
g.drawImage(offimage, 0, 0, this);
fresh_flag = 0;
}
if(imageTracker.checkID(frames1))
{
gBuffer.drawImage(image, 0, 0, this);
if(display_type % 2 == 0)
if(size_flag == 0)
{
g.drawImage(Buffer, 0, 0, this);
return;
} else
{
g.drawImage(Buffer, 0, 0, 2 * before_width, 2 * before_height, this);
return;
}
if(size_flag == 0)
{
g.drawImage(Buffer, before_width, before_height, 0, 0, 0, 0, before_width, before_height, this);
return;
}
g.drawImage(Buffer, 2 * before_width, 2 * before_height, 0, 0, 0, 0, before_width, before_height, this);
}
}
public void update(Graphics g)
{
paint(g, mImage);
}
public void destroy()
{
running = false;
clockThread = null;
}
public void getdata()
{
System.out.println("getdata()..");
try
{
System.out.println("sock: " + sock);
pw = new PrintWriter(sock.getOutputStream(), true);
pw.println("0110");
System.out.println("send to sever:");
is = sock.getInputStream();
counter = 0;
sizecounter = 0;
for(s1 = Integer.toBinaryString(is.read());
s1.length() < 8;
s1 = '0' + s1);
for(s2 = Integer.toBinaryString(is.read());
s2.length() < 8;
s2 = '0' + s2);
s2 = s1 + s2;
sizecounter = Integer.parseInt(s2, 2);
if(sizecounter > 0)
byte_image = new byte[sizecounter];
s3 = Integer.toBinaryString(is.read());
j1 = Integer.parseInt(s3, 2);
s4 = Integer.toBinaryString(is.read());
j2 = Integer.parseInt(s4, 2);
length = sizecounter;
for(start = 0;
start < sizecounter - 1;)
{
len0 = is.read(byte_image, start, length);
if(len0 != 0)
{
start = len0 + start;
length = length - len0;
}
}
if(j2 != 0)
{
pw.close();
sock.close();
Container container;
for(container = getParent();
!(container instanceof Frame);
container = container.getParent());
Frame frame = (Frame)container;
YesNoDialog yesnodialog = new YesNoDialog(frame, "Too many users! Please try later.");
yesnodialog.show();
if(sint == 0)
{
pw.close();
sock.close();
boolean flag = false;
do
{
flag = false;
try
{
sock = new Socket(ip, port);
}
catch(Throwable _ex)
{
for(Container container1 = getParent();
!(container1 instanceof Frame);
container1 = container1.getParent());
Frame frame1 = (Frame)container;
YesDialog yesdialog = new YesDialog(frame1, "Video connection to camera failed.Please try again.");
yesdialog.show();
try
{
Thread.sleep(2000L);
}
catch(Exception _ex2) { }
flag = true;
}
} while(flag);
flag = false;
return;
}
if(sint == 1)
Thread.sleep(0x4c4b40L);
}
if(sizecounter != 0)
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
mImage = toolkit.createImage(byte_image, 0, sizecounter);
imageTracker = new MediaTracker(this);
toolkit = null;
byte_image = null;
imageTracker.addImage(mImage, frames1);
imageTracker.waitForID(frames1);
t1 = System.currentTimeMillis();
before_width = mImage.getWidth(this);
before_height = mImage.getHeight(this);
if(before_width == -1 || before_height == -1)
return;
System.out.println("w: " + w + ", b: " + before_width);
if(w != before_width || h != before_height)
fresh_flag = 1;
w = before_width;
h = before_height;
Buffer = createImage(before_width, before_height);
gBuffer = Buffer.getGraphics();
Graphics g = getGraphics();
paint(g, mImage);
g = null;
imageTracker = null;
System.gc();
frames1++;
frames++;
elapsetime = t1 - t0;
if(elapsetime > 5000L)
{
fps = (1000D * (double)frames) / (double)elapsetime;
fps = fps + 1.0D;
t0 = t1;
frames = 0;
empty = 2;
}
} else
{
return;
}
}
catch(Throwable throwable)
{
throwable.printStackTrace();
}
pw = null;
is = null;
System.gc();
}
public void stop()
{
try
{
pw.close();
sock.close();
return;
}
catch(IOException ioexception)
{
System.out.println(ioexception);
}
}
public void test1()
{
size_flag = 0;
fresh_flag = 1;
repaint();
}
public void test2()
{
size_flag = 1;
fresh_flag = 1;
repaint();
}
public void test3()
{
display_type++;
if(display_type % 4 == 1)
rotation = 1.5707963267948966D;
else
if(display_type % 4 == 2)
rotation = 3.1415926535897931D;
else
if(display_type % 4 == 3)
rotation = 4.7123889803846897D;
fresh_flag = 1;
if(frames1 != 0)
repaint();
}
}
 
后退
顶部