import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.net.*; import java.io.*; public class SyrrKlient extends Applet implements ActionListener, Runnable { int i = 0, j = 0, r, g, b, x, y, z, w; Button nupp = new Button("Ühenda"); TextField tekst = new TextField(); TextArea v2li = new TextArea(); //Panel paneel = new Panel() Panel paneel2 = new Panel(new GridLayout(2, 1)); Panel nupupaneel = new Panel(new GridLayout(2, 1)); PrintWriter valja; BufferedReader sisse; Color[] v2rvid = {Color.white, Color.yellow, Color.black, Color.blue, Color.red, Color.green}; String[] v2rvid2 = {"", "kollane", "must", "sinine", "punane", "roheline"}; int[] asd = {0, 1, 2, 3}; String[] asd2 = {"", "ring", "ruut", "joon"}; public SyrrKlient() { setLayout(new BorderLayout()); nupupaneel.add(tekst); nupupaneel.add(nupp); paneel2.add(v2li); paneel2.add(nupupaneel); add(paneel2, BorderLayout.SOUTH); nupp.addActionListener(this); tekst.addActionListener(this); } public void paint(Graphics q) { r = (int)( 240 * Math.random()); g = (int)( 240 * Math.random()); b = (int)( 240 * Math.random()); q.setColor(v2rvid[i]); x = (int)( 200 * Math.random()); y = (int)( 200 * Math.random()); z = (int)( 200 * Math.random()); w = (int)( 200 * Math.random()); switch(asd[j]) { case 1: q.fillOval(x, y, z, w); break; case 2: q.fillRect(x, y, z, w); break; case 3: q.drawLine(x, y, z, w); break; } } public void actionPerformed(ActionEvent e) { try { if(e.getSource() == nupp) { Socket sc = new Socket("localhost", 3001); valja = new PrintWriter(sc.getOutputStream(), true); sisse = new BufferedReader(new InputStreamReader(sc.getInputStream())); new Thread(this).start(); v2li.setEnabled(false); } else if(e.getSource() == tekst) { valja.println(tekst.getText()); tekst.setText(""); } } catch(Exception ex) { ex.printStackTrace(); } } public void run() { try { for(String rida = sisse.readLine(); rida != null; rida = sisse.readLine()) { boolean change = false; v2li.append(rida+"\n"); String jeehaw[] = rida.split(" "); for(int t = 0; t < asd2.length; t++) { for(int e = 0; e < jeehaw.length; e++) { if(jeehaw[e].equals(asd2[t])) { j = t; change = true; } } } for(int t = 0; t < v2rvid2.length; t++) { for(int e = 0; e < jeehaw.length; e++) { if(jeehaw[e].equals(v2rvid2[t])) { i = t; change = true; } } } if(change) { repaint(); } } } catch(Exception ex) { ex.printStackTrace(); } } public static void main(String[] argumendid) { Frame f = new Frame("Sürruste klient"); f.add(new SyrrKlient()); f.setSize(500, 650); f.setVisible(true); f.addWindowListener(new Raamikuular()); } static class Raamikuular extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } }