Hi,
When I ran the applet in Eclipse, the applet worked.
But when I try the applet in HTML, it didn't show the interface, it showed:
Runtime Exception
java.lang.NoClassDefFoundError: jssc/SerialPortException
Here are my codes.
import java.applet.Applet; import java.awt.Button; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class panel extends Applet implements ActionListener { // parameters Button wButton = new Button("W"); Button aButton = new Button("A"); Button dButton = new Button("D"); Button xButton = new Button("X");; Button oButton = new Button("Start");; Button cButton = new Button("Stop"); sd2bak SD = new sd2bak(); TextArea display = new TextArea();; // show log String command = "."; // redundancy for actions boolean status = false; // check connection /** web user interface */ public void init() { setLayout(null); // buttons position wButton.setBounds(70, 20, 50, 50); aButton.setBounds(20, 70, 50, 50); dButton.setBounds(120, 70, 50, 50); xButton.setBounds(70, 120, 50, 50); display.setBounds(200, 20, 130, 200); oButton.setBounds(20, 120, 50, 50); cButton.setBounds(120, 120, 50, 50); // add buttons to Layout add(wButton); add(aButton); add(dButton); add(xButton); add(display); add(oButton); add(cButton); // Listen to action whenever pressed wButton.addActionListener(this); aButton.addActionListener(this); dButton.addActionListener(this); xButton.addActionListener(this); oButton.addActionListener(this); cButton.addActionListener(this); } /** Send to COM */ public void send(String command) { SD.tocom(command); command = "."; } /** Open port and socket */ public void openport() { SD.openpt(); show("connected"); } /** Close port and socket */ public void closeport() { SD.closept(); show("Disconnected"); } /** buttons action */ public void actionPerformed(ActionEvent evt) { if (evt.getSource() == oButton && status == false) { openport(); status = true; } else if (evt.getSource() == oButton) { show("Already Connected"); } else if (status == true) { if (evt.getSource() == wButton) { // action for button w command = "w"; work(); } else if (evt.getSource() == aButton) { // action for button a command = "a"; work(); } else if (evt.getSource() == dButton) { // action for button d command = "d"; work(); } else if (evt.getSource() == xButton) { // action for button x command = "x"; work(); } else if (evt.getSource() == cButton) { closeport(); status = false; } } else show("Not conected"); } /* actions detail */ public void work() { // servget client_actions = new servget(); // send actions to server send(command); // send actions show(command); command = ".";// reset } /* display area */ public void show(String txt) { display.append(txt + "\n"); } }// EOF
import jssc.SerialPort; import jssc.SerialPortException; public class sd2bak { SerialPort serialPort = new SerialPort("COM4"); /** Open port */ public void openpt() { try { serialPort.openPort(); } catch (SerialPortException ex) { } try { serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (SerialPortException ex) { } } /** Write to COM */ public void tocom(String command) { try { serialPort.writeBytes(command.getBytes()); } catch (SerialPortException ex) { } } /** Close port */ public void closept() { try { serialPort.closePort(); } catch (SerialPortException ex) { } } }// EOF