import java.net.*; import java.io.*; import java.awt.*; import java.applet.*; import java.awt.event.*; public class rs232c_Applet extends Applet implements ActionListener { Button btnRTS; Button btnDTR; Button btnCLR; OutputStream sout; String host; public void init() { setLayout(new GridLayout(1,0,20,0)); btnRTS=new Button("RTS"); btnDTR=new Button("DTR"); btnCLR=new Button("CLR"); btnRTS.setBackground(Color.green); btnDTR.setBackground(Color.green); btnRTS.addActionListener(this); btnDTR.addActionListener(this); btnCLR.addActionListener(this); add(btnRTS); add(btnDTR); add(btnCLR); host=getCodeBase().getHost(); if(host=="") host="localhost"; } void request(char data) { try { Socket sock=new Socket(host,2100); sout=sock.getOutputStream(); sout.write(data); sout.close(); sock.close(); } catch(Exception ex) { System.out.println(ex); } } public void actionPerformed(ActionEvent ev) { if(ev.getSource() instanceof Button) { Button btn=(Button)ev.getSource(); if(btn==btnRTS) { btnRTS.setBackground(Color.red); btnDTR.setBackground(Color.green); request((char)2); } if(btn==btnDTR) { btnRTS.setBackground(Color.green); btnDTR.setBackground(Color.red); request((char)1); } if(btn==btnCLR) { btnRTS.setBackground(Color.green); btnDTR.setBackground(Color.green); request((char)0); } } } }