import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.net.*; import java.io.*; public class Liides extends Applet implements ActionListener,Runnable{ TextField sisestus=new TextField(); Button lisa=new Button(" Lisa nimi "); Button muuda=new Button(" Muuda andmeid "); TextArea sisu=new TextArea(); PrintWriter valja; BufferedReader sisse; boolean veel=false; boolean admin=false; public Liides(){ Panel p=new Panel(new GridLayout(1, 2)); p.add(lisa); p.add(muuda); setLayout(new BorderLayout()); add(sisestus,BorderLayout.SOUTH); add(p, BorderLayout.NORTH); // add(lisa,BorderLayout.NORTH); // add(muuda,BorderLayout.NORTH); add(sisu,BorderLayout.CENTER); lisa.addActionListener(this); muuda.addActionListener(this); sisestus.addActionListener(this); sisestus.setEnabled(false); sisu.setEnabled(false); } public void actionPerformed(ActionEvent e){ try{ if(e.getSource()==lisa){ Socket sc=new Socket("193.40.81.13",3001); valja = new PrintWriter(sc.getOutputStream(),true); sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); lisa.setVisible(false); muuda.setVisible(false); sisu.setEnabled(true); sisu.setText(""); sisestus.setEnabled(true); validate(); veel=true; new Thread(this).start(); } if(e.getSource()==muuda){ Socket sc=new Socket("193.40.81.13",3001); valja = new PrintWriter(sc.getOutputStream(),true); sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); lisa.setVisible(false); muuda.setVisible(false); sisu.setEnabled(true); sisu.setText(""); sisestus.setEnabled(true); validate(); admin=true; veel=false; new Thread(this).start(); valja.println("1admin321"); valja.println(".t"); } if (e.getSource()==sisestus){ if(sisestus.getText().equals(".s") && admin==true){ valja.println(sisestus.getText()); //System.out.println("siin olen"); valja.println(sisu.getText().replaceAll("\n", "#")); //valja.println(sisu.getText()); } else{ valja.println(sisestus.getText()); } sisestus.setText(""); } }catch(Exception ex){ex.printStackTrace();} } public void run(){ try{ while(veel){ String rida=sisse.readLine(); if(rida!=null){ sisu.append(rida+"\n"); } else { veel=false; } } while(admin){ String rida=sisse.readLine(); // if(!rida.equals("Tere tulemast 6pilaste serverisse!") || !rida.equals("Sisesta kasutajanimi:")){ if(rida!=("Tere tulemast 6pilaste serverisse!")){ sisu.append(rida+"\n"); } if (rida==null) { admin=false; } } sisu.setText(""); sisu.append("Ühendus katkes!"); lisa.setVisible(true); muuda.setVisible(true); validate(); }catch(Exception ex){ex.printStackTrace();} } public static void main(String argumendid[]){ Frame f=new Frame("Andmebaasi klient"); f.add(new Liides()); f.setSize(500, 400); f.setVisible(true); } }