public class Form extends Applet
Листинг 5
. Файл Form.java
import java.applet.*; import java.awt.*; import java.net.*; import java.io.*; import java.util.*;
public class Form extends Applet implements Runnable { private Thread m_store = null;
TextField txtName; TextField txtEMail; TextArea txta; Button btnGetText;
public void init() { Label lbName; Label lbEMail; Label lbPress;
lbName = new Label("Enter your name:");
lbEMail = new Label( "Enter your E-Mail address:");
add(lbName);
txtName = new TextField("Your name", 40);
add(txtName);
add(lbEMail);
txtEMail = new TextField("your@email", 40);
add(txtEMail);
btnGetText = new Button("Send!");
add(btnGetText);
txta = new TextArea(8, 65);
add(txta);
setBackground(Color.yellow);
}
public void paint(Graphics g) { setBackground(Color.yellow);
Dimension dimAppWndDimension = getSize();
g.setColor(Color.black);
g.drawRect(0, 0, dimAppWndDimension.width - 1, dimAppWndDimension.height - 1);
}
public boolean action(Event evt, Object obj) { Button btn;
if(evt.target instanceof Button) { btn = (Button)evt.target;
if(evt.target.equals(btnGetText)) { startTransaction();
} else return false; return true; } return false; }
void startTransaction() { m_store = new Thread(this);
m_store.start();
}
public void stop() { if (m_store != null) { m_store.stop();
m_store = null; } }
public void run() { URL u; URLConnection c; PrintStream ps; DataInputStream is;
try { String szSourceStr = txtName.getText() + ", " + txtEMail.getText();
String szReceived; String szURL = "http://frolov/scripts/store.exe";
u = new URL(szURL);
c = u.openConnection();
ps = new PrintStream( c.getOutputStream());
ps.println(szSourceStr);
ps.close();
is = new DataInputStream( c.getInputStream());
szReceived = is.readLine();
is.close();
txta.appendText(szReceived + "\r\n");
repaint();
} catch (Exception ioe) { showStatus(ioe.toString());
stop();
} } }
Исходный текст документа HTML, который был подготовлен для нас системой Java Workshop, мы немного отредактировали, изменив параметр CODEBASE (листинг 6).