Hi,
kann you try to see my Problem - To sign My Programm.
I don't have any more Nerve to make that, and I don't understand well English.
Im Using the IBM COM API
http://public.planetmirror.com/pub/...bm/1.3.0/win32/
ibm-javacomm-win32-x86.zip
Thanks, if you can help me.
You cann send the Files (JAR, policy, security) at: boristdi@yahoo.com
import javax.swing.*;
import java.awt.Container;import java.awt.event.ActionEvent;
import javax.comm.NoSuchPortException;
import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;
import java.awt.Container;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.Color;
import javax.comm.PortInUseException;
import java.io.InputStream;
import java.io.IOException;
import javax.swing.JTextField;
import java.awt.Panel;
import java.awt.Choice;
import java.util.Enumeration;
import java.io.OutputStream;
import java.awt.Label;
import javax.comm.UnsupportedCommOperationException;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JApplet;
import java.awt.Color;
import java.awt.event.*;
import java.io.*;
public class Myapplet extends JApplet implements ItemListener {
Choice aw1;
Choice aw2;
Choice aw3;
Choice aw4;
JButton vidStr=new JButton("Start videostream");
JButton on=new JButton("On");
JButton off=new JButton("Off");
JButton set2=new JButton("Set");
JButton mS=new JButton("Make Snapshot");
JTextField tf=new JTextField();
JTextField tf2=new JTextField();
String name;
String name2;
public void init() {
Container c = getContentPane();
Panel panel = new Panel();
panel.setLayout(null);
Label header = new Label("1. Videostream");
header.setFont(new Font("Serif", Font.BOLD, 25));
header.setBounds(20, 10, 180, 30);
panel.add(header);
Label header2 = new Label("resolution:");
header2.setFont(new Font("Serif", Font.PLAIN, 20));
header2.setBounds(50, 40, 100, 30);
panel.add(header2);
aw1 = new Choice();
aw1.setFont(new Font("Serif", Font.PLAIN, 15));
aw1.add("352x288 pixel");
aw1.add("176x144 pixel");
aw1.add("704x576 pixel");
aw1.setBounds(50, 75, 130, 40);
Label header3 = new Label("compression:");
header3.setFont(new Font("Serif", Font.PLAIN, 20));
header3.setBounds(50, 105, 150, 30);
panel.add(header3);
aw2 = new Choice();
aw2.setFont(new Font("Serif", Font.PLAIN, 15));
aw2.add("medium(50%)");
aw2.add("min(0%)");
aw2.add("low(30%)");
aw2.add("high(70%)");
aw2.add("very high(90%)");
aw2.setBounds(50, 140, 130, 40);
//Button Start videostream
vidStr.setBounds(50, 180, 137, 30);
Label header4 = new Label("2. Cam & Light");
header4.setFont(new Font("Serif", Font.BOLD, 25));
header4.setBounds(20, 220, 180, 30);
panel.add(header4);
Label header5 = new Label("(auto-off after 30 min)");
header5.setFont(new Font("Serif", Font.PLAIN, 18));
header5.setForeground(Color.red);
header5.setBounds(40, 245, 200, 30);
panel.add(header5);
//Button Cam On/Off
on.setBounds(30, 280, 80, 30);
off.setBounds(130, 280, 80, 30);
Label header6 = new Label("3. Motor voltage");
header6.setFont(new Font("Serif", Font.BOLD, 25));
header6.setBounds(20, 320, 180, 30);
panel.add(header6);
Label header7 = new Label("(Range:0;30-260 dV, integer)");
header7.setFont(new Font("Serif", Font.PLAIN, 18));
header7.setBounds(20, 350, 215, 30);
panel.add(header7);
//Textfeld + Button
tf.setBounds(40, 385, 80, 27);
panel.add(tf);
set2.setBounds(140, 385, 60, 27);
Label header8 = new Label("4. Stopwatch:");
header8.setFont(new Font("Serif", Font.BOLD, 25));
header8.setBounds(20, 420, 180, 30);
panel.add(header8);
tf2.setBounds(40, 455, 80, 27);
panel.add(tf2);
Label header8a = new Label("ms");
header8a.setFont(new Font("Serif", Font.BOLD, 15));
header8a.setBounds(125, 465, 25, 20);
panel.add(header8a);
Label header9 = new Label("5. Snapshot");
header9.setFont(new Font("Serif", Font.BOLD, 25));
header9.setBounds(20, 490, 180, 30);
panel.add(header9);
Label header10 = new Label("resolution:");
header10.setFont(new Font("Serif", Font.PLAIN, 20));
header10.setBounds(50, 515, 100, 30);
panel.add(header10);
aw3 = new Choice();
aw3.setFont(new Font("Serif", Font.PLAIN, 15));
aw3.add("352x288 pixel");
aw3.add("176x144 pixel");
aw3.add("704x576 pixel");
aw3.setBounds(50, 545, 130, 40);
Label header11 = new Label("compression:");
header11.setFont(new Font("Serif", Font.PLAIN, 20));
header11.setBounds(50, 570, 150, 30);
panel.add(header11);
aw4 = new Choice();
aw4.setFont(new Font("Serif", Font.PLAIN, 15));
aw4.add("low");
aw4.add("min");
aw4.add("medium");
aw4.add("high");
aw4.add("very high");
aw4.setBounds(50, 605, 130, 40);
// Button
mS.setBounds(50, 645, 140, 27);
panel.add(aw1);
panel.add(aw2);
panel.add(aw3);
panel.add(aw4);
panel.add(vidStr);
panel.add(on);
panel.add(off);
panel.add(set2);
panel.add(mS);
aw1.addItemListener(this);
c.add(panel);
on.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
Enumeration portList=null;
CommPortIdentifier portId=null;
SerialPort serialPort=null;
OutputStream outputStream=null;
InputStream inputStream=null;
String comando = "?; // Komando zum Starten senden
JPanel nachricht22 = new JPanel();
JOptionPane pane22 = new JOptionPane(nachricht22);
JDialog dialog22 = pane22.createDialog(null, "port versuchen ");
dialog22.show();
try{ // Port 鰂fnen
portId = CommPortIdentifier.getPortIdentifier("COM1");
} catch(NoSuchPortException nspe){tf.setText(nspe.toString());}
try { // Serial Port 鰂fnen
serialPort = (SerialPort) portId.open("Teste", 2000);
} catch (PortInUseException piue) {tf.setText(piue.toString());}
try { // Eingabe-/Ausgabestreams 鰂fnen
outputStream = serialPort.getOutputStream();
inputStream = serialPort.getInputStream();
} catch (IOException ioe) {tf.setText(ioe.toString());}
try { // Port Parameters
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException ucoe) {tf.setText(ucoe.toString());}
try { // Schicke das Befehl
//outputStream.write(comando.getBytes());
/*JPanel nachricht1 = new JPanel();
JOptionPane pane1 = new JOptionPane(nachricht1);
JDialog dialog1 = pane1.createDialog(null, "R點kgabe= "+inputStream.read());
dialog1.show();
*/
outputStream.close();
inputStream.close();
} catch (IOException ioex) {tf.setText(ioex.toString());}
}
});
off.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
String message = ""; // Komando zum Starten senden
JPanel nachricht = new JPanel();
JOptionPane pane = new JOptionPane(nachricht);
JDialog dialog = pane.createDialog(null, "HaalloooooOOoo");
dialog.show();
//SendenSerialPort mp=new SendenSerialPort(message);
}
});
}
public void itemStateChanged(ItemEvent ie) {
repaint();
}
}
Enschuldigung fur mein deutch, hab es shon lange nicht gesprochen.
hab die applet in c:\temp gemacht
put Myapplet in c:\temp
Unzipped der zipfile (mit path namen) und hab die bin sachen copiert zum:
Unziped the zipfile (keep path names) and copied the bin stuff to:
Copied the bin stuff to
C:\Program Files\Java\jdk1.5.0_03\jre\bin
C:\Program Files\Java\jdk1.5.0_03\bin
C:\Program Files\Java\jre1.5.0_03\bin
Die lib sachen im:
the lib stuff to
C:\Program Files\Java\jre1.5.0_03\lib
C:\Program Files\Java\jdk1.5.0_03\lib
C:\Program Files\Java\jdk1.5.0_03\jre\lib
(the ext stuff goes in the ext directory)
das hier
added this
grant codeBase "file://C:/*" {
permission java.security.AllPermission;
};
Im java.policy gezetzt im:
to the java.policy in
C:\Program Files\Java\jre1.5.0_03\lib\security
C:\Program Files\Java\jdk1.5.0_03\lib\security
C:\Program Files\Java\jdk1.5.0_03\jre\lib\security
Die html file geoffenet im c:\temp
Opened the html file in c:\temp:
<DIV id="lblOutputText">Output comes here</DIV>
<DIV id="dvObjectHolder">Applet comes here</DIV>
<script>
if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:
document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"java:Myapplet.java\"" +
"height='700' width='700' onError=\"changeObject();\"" +
">" +//"<param name=\"archive\" value=\"sTest.jar\">" +
"<param name=\"mayscript\" value=\"Y\">" +
"</object>";
}else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE
document.getElementById('dvObjectHolder').innerHTML ="<object ID='appletTest1'
classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +
" height='700' width='700' >" +
"<param name=\"code\" value=\"Myapplet.java\" />" +// "<param name=\"archive\" value=\"sTest.jar\">" +
" </object>"
}
</script>
keen problemen, bitte printStacktrace mit jeder try sachen:
No problems, please printStacktract on all try stuff
what does this do for you, run as application and applet
c:\temp\test.htm
<DIV id="lblOutputText">Output comes here</DIV>
<DIV id="dvObjectHolder">Applet comes here</DIV>
<script>
if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:
document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"java:test.class\"" +
"height='700' width='700' onError=\"changeObject();\"" +
">" +//"<param name=\"archive\" value=\"sTest.jar\">" +
"<param name=\"mayscript\" value=\"Y\">" +
"</object>";
}else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE
document.getElementById('dvObjectHolder').innerHTML ="<object ID='appletTest1' classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +
" height='700' width='700' >" +
"<param name=\"code\" value=\"test.class\" />" +// "<param name=\"archive\" value=\"sTest.jar\">" +
" </object>"
}
</script>
c:\temp\test.java
/*
* Created on May 31, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author 209117
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
import javax.comm.*;
import java.io.*;
import java.util.Enumeration;
import java.applet.*;
public class test extends Applet implements Runnable {
public static void main(String[] args) {
new test();
}
public test() {
new Thread(this).start();
}
public void init(){
System.out.println("this is init");
}
public void run() {
try{
System.out.println("this is run");
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null;
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = "Parallel";
break;
case CommPortIdentifier.PORT_SERIAL:
type = "Serial";
break;
default: /// Shouldn't happen
type = "Unknown";
break;
}
System.out.println(port.getName() + ": " + type);
if(port.getName().toLowerCase().indexOf("com1")!=-1){
portId = port;
}
}
CommPort port = portId.open("Application Name", 3000);
OutputStream os = port.getOutputStream();
os.write("okidoki".getBytes("UTF-8"));
System.out.println("done, no problems");
}catch(Exception e){
e.printStackTrace();
}
}
}
commands
c:
cd \temp\test
javac test.java
java test
open c:\test\test.htm in a browser and check console output.