import java.io.*; import java.net.*; import java.applet.Applet; import java.awt.*; import java.awt.Label; import java.awt.event.*; //import java.awt.event.ActionListener; //import java.awt.event.MouseListener; //import java.awt.event.ActionEvent; //import java.awt.event.WindowAdapter; //import java.awt.event.WindowEvent; public class mailer extends Applet implements MouseListener{ TextArea tekst=new TextArea("Siia kirjuta kirja sisu ",27,15, TextArea.SCROLLBARS_VERTICAL_ONLY); TextField aadress=new TextField("Siia kirjuta aadress"); TextField teema=new TextField("siia kirjuta kirja teema"); //TextArea test=new TextArea("test",10,10); Button saada=new Button("SAADA"); Button uuesti=new Button("UUESTI"); String server; String saatja="javaappletikasutaja@hk.tpu.ee"; String pealkiri="blahhh"; public mailer(){ setLayout(new BorderLayout()); Panel vasak=new Panel(new GridLayout(20,1)); //vasak.add(test,BorderLayout.NORTH); vasak.add(saada, BorderLayout.NORTH); add(vasak,BorderLayout.WEST); saada.addMouseListener(this); Panel parem=new Panel(new BorderLayout()); Panel grid1=new Panel(new GridLayout(2,1)); grid1.add(aadress); grid1.add(teema); parem.add(grid1, BorderLayout.NORTH); parem.add(tekst, BorderLayout.CENTER); add(parem, BorderLayout.CENTER); } public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseClicked(MouseEvent e){ try{ System.out.println("cmd ok"); /* ---et kui viskaSks ekraani tühjaks ja teeks uue logiakna. removeAll(); setLayout(new BorderLayout()); TextArea log=new TextArea("",27,15); add(log, BorderLayout.CENTER); validate(); */ //vasak.remove(saada, BorderLayout.NORTH); //vasak.add(uuesti, BorderLayout.NORTH); if (saada.getLabel().equals("SAADA")){ //tekst.append("saadada"); String kiri=tekst.getText(); tekst.setText(""); Socket sc=new Socket("193.40.81.3", 25); PrintWriter valja=new PrintWriter(sc.getOutputStream(), true); BufferedReader sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); valja.println("helo "+"tera.hk.tpu.ee"); tekst.append("-> helo "+"tera.hk.tpu.ee"+"\n"); tekst.append("INFO:connecting..."+"\n"); tekst.append(sisse.readLine()+"\n"); tekst.append(sisse.readLine()+"\n"); valja.println("mail from: "+saatja); tekst.append("-> mail from:"+saatja+"\n"); tekst.append(sisse.readLine()+"\n"); String mailto=aadress.getText(); valja.println("rcpt to: "+mailto); tekst.append("-> rcpt to: "+mailto+"\n"); tekst.append(sisse.readLine()+"\n"); valja.println("DATA"); tekst.append("-> DATA\n"); tekst.append(sisse.readLine()+"\n"); String subject=teema.getText(); valja.println("Subject: "+subject); tekst.append("-> Subject: "+subject+"\n"); valja.println("From: "+"\"Javaapplet\" <"+saatja+">"); tekst.append("-> From: "+"\"Javaapplet\" <"+saatja+">\n"); valja.println(kiri); tekst.append(kiri+"\n"); valja.println("."); tekst.append("-> .\n"); tekst.append(sisse.readLine()+"\n"); valja.println("quit"); tekst.append("-> quit\n"); tekst.append(sisse.readLine()+"\n"); sc.close(); //tekst.append("INFO:ühendus mailiserveriga lõpetatud"); saada.setLabel("UUESTI"); } else { if (saada.getLabel().equals("UUESTI")){ tekst.setText("Siia kirjuta kirja sisu "); aadress.setText("Siia kirjuta aadress"); teema.setText("siia kirjuta kirja teema"); saada.setLabel("SAADA"); } } }catch(Exception exp){ tekst.append(exp.toString()+"\n"); } } public static void main(String argumendid[]){ Frame f=new Frame(); f.add(new mailer()); f.setSize(650,420); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } }