// programm millega saab lugeda viimast kirja import java.io.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.util.*; public class Lugeja3aa extends Applet implements ActionListener { BufferedReader sisse; String server; String nimi; String parool; String rida; int kirjadearv=0; Label label1=new Label("Server:"); TextField tf2=new TextField("lin2.tpu.ee"); Label label2=new Label("Kasutajanimi:"); TextField tf4=new TextField(); Label label3=new Label("Parool:"); TextField tf6=new TextField(); Button b2=new Button("Sisene"); TextArea ta1=new TextArea(); Button b1=new Button("Välju"); public Lugeja3aa() { setLayout(null); label1.setBounds(10,10,100,20); // (x, y, width, height) tf2.setBounds(112,10,200,20); label2.setBounds(10,35,100,20); tf4.setBounds(112,35,200,20); label3.setBounds(10,60,100,20); tf6.setBounds(112,60,200,20); b2.setBounds(260,87,50,24); ta1.setBounds(10,190,570,350); b1.setBounds(530,545,50,24); add(label1); add(tf2); add(label2); add(tf4); add(label3); add(b2); add(tf6); add(ta1); add(b1); tf6.setEchoChar('*'); // parooli sisestamiseks tf2.addActionListener(this); tf4.addActionListener(this); tf6.addActionListener(this); b1.addActionListener(this); b2.addActionListener(this); } // end of public Lugeja //loetakse sisse server, kasutajanimi ja parool public void actionPerformed(ActionEvent e) { PrintWriter valja; if(e.getSource()==b2){ try{ server=tf2.getText().trim(); nimi=tf4.getText().trim(); parool=tf6.getText().trim(); // luuakse ühendus lugemiseks Socket sc1=new Socket(server, 110); sisse=new BufferedReader(new InputStreamReader(sc1.getInputStream())); valja=new PrintWriter(sc1.getOutputStream(), true); valja.println("user "+nimi); valja.println("pass "+parool); valja.println("list"); String viimaneKirjaRida = ""; rida=sisse.readLine(); while(!rida.equals(".")){ kirjadearv++; System.out.println(rida); viimaneKirjaRida = rida; rida=sisse.readLine(); } // end while kirjadearvu lugemiseks if(kirjadearv > 0){ System.out.println(viimaneKirjaRida ); System.out.println("RETR "+ (new StringTokenizer(viimaneKirjaRida , " ")).nextToken()); valja.println("RETR "+ (new StringTokenizer(viimaneKirjaRida , " ")).nextToken()); int reanr=0; while(!(rida=sisse.readLine()).equals(".")){ ta1.append(rida + "\n"); reanr++; } // end while kirja trükkimiseks } // endif kirjanumbri teadasaamiseks sc1.close(); }catch(Exception viga){ System.out.println(viga); } } if(e.getSource()==b1){ // väljumisnupp System.exit(0); } // endif } // end of public void actionPerformed // aken nähtavaks public static void main(String argumendid[]) throws Exception { Frame f=new Frame("POSTKAST"); f.setSize(600, 600); f.setBackground(Color.LIGHT_GRAY); f.add(new Lugeja3aa()); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } // end of public static void main } // end of public class Lugeja // java.net.ConnectException: Connection refused: connect