import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; public class Kiri extends Applet implements ActionListener { TextField tf_kellele = new TextField(); TextField tf_kellelt = new TextField(); TextField tf_subject = new TextField(); TextArea ta_sisu = new TextArea("", 20, 50, TextArea.SCROLLBARS_VERTICAL_ONLY); Label l_kellele = new Label("Kellele: "); Label l_kellelt = new Label("Kellelt: "); Label l_subject = new Label("Pealkiri:"); Label l_sisu = new Label("Kirja sisu:"); Label l_tyhi = new Label(" "); Button nupp = new Button("Saada kiri"); public static void main(String argumendid[]){ Frame f=new Frame("Kiri!"); f.setSize(400, 450); Applet ap=new Kiri(); ap.init(); f.add(ap); f.setVisible(true); } public void init() { setLayout(new BorderLayout()); Panel p_n = new Panel(new GridLayout(2, 4)); p_n.add(l_kellele); p_n.add(tf_kellele); p_n.add(l_kellelt); p_n.add(tf_kellelt); p_n.add(l_subject); p_n.add(tf_subject); p_n.add(l_tyhi); p_n.add(l_tyhi); add(p_n, BorderLayout.NORTH); Panel p_s = new Panel(new BorderLayout()); Panel p_s_n = new Panel(new GridLayout(1, 2)); p_s_n.add(l_sisu); p_s_n.add(nupp); p_s.add(p_s_n, BorderLayout.NORTH); p_s.add(ta_sisu, BorderLayout.CENTER); add(p_s, BorderLayout.SOUTH); nupp.addActionListener(this); } public void actionPerformed(ActionEvent e) { String kellele = tf_kellele.getText(); String kellelt = tf_kellelt.getText(); String subject = tf_subject.getText(); String sisu = ta_sisu.getText(); try { Socket sc = new Socket("www.rk.ee", 25); PrintWriter valja = new PrintWriter(sc.getOutputStream(), true); valja.println("mail from: "+kellelt); valja.println("rcpt to: "+kellele); valja.println("Subject: "+subject); valja.println("DATA"); valja.println(sisu); valja.println("."); sc.close(); ta_sisu.setText(""); tf_kellele.setText(""); tf_kellelt.setText(""); tf_subject.setText(""); } catch(Exception ex) { ta_sisu.setText(""+ex); } } }