import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; public class Meldimine extends Frame{ TextField teade=new TextField("Vőta uhendus masinaga"); Button Uhendus=new Button("Vőtan uhenduse!"); Label lnimi=new Label(""); TextField nimi=new TextField(30); Label lparool=new Label(""); TextField parool=new TextField(30); public Meldimine(){ setLayout(new BorderLayout()); setFont(new Font("Helvetica",Font.PLAIN,12)); setBackground(Color.gray); nimi.setEditable(true); parool.setEditable(true); teade.setEditable(false); Panel Vasakpaneel=new Panel(); Panel Parempaneel=new Panel(); Vasakpaneel.setLayout(new BorderLayout()); Vasakpaneel.add("North",lnimi); Vasakpaneel.add("South",nimi); Parempaneel.setLayout(new BorderLayout()); Parempaneel.add("North",lparool); Parempaneel.add("South",parool); add("North",teade); add("West",Vasakpaneel); add("East",Parempaneel); add("South",Uhendus); setVisible(true); pack(); show(); Uhendus.addMouseListener( new Andmednetti(this) ); } public static void main(String argumendid[]){ new Meldimine(); } } class Andmednetti extends MouseAdapter{ Meldimine m; public Andmednetti(Meldimine um){ m=um; } public void mousePressed(MouseEvent e){ String n=m.nimi.getText(); String p=m.parool.getText(); System.out.println("Hiir alla"); try{ Socket sc=new Socket("localhost", 5656); BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); System.out.println("Ootab vastust"); String vastus=sisse.readLine(); System.out.println("vastus="+vastus); m.teade.setText(vastus); m.lnimi.setText("Kirjuta oma nimi:"); m.nimi.setEditable(true); PrintWriter valja=new PrintWriter(sc.getOutputStream(), true); valja.println(n); String vastus2=sisse.readLine(); m.teade.setText(vastus2); m.lparool.setText("Kirjuta oma parool"); m.parool.setEditable(true); valja.println(p); if(vastus2.equals("Sisesta oma parool")){ String vastus3=sisse.readLine(); m.teade.setText(vastus3); } valja.close(); } catch(Exception ex){ ex.printStackTrace(); } } }