import java.net.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.applet.Applet; public class klient extends Applet implements ActionListener { class kuulariloim extends Thread { public kuulariloim() { start(); } public void run() { while (klient.kas_sees==true) { try { String puhver=sisse.readLine(); System.out.println(puhver); joonista(puhver); try{Thread.sleep(10);}catch(Exception i){} } catch(Exception u) { System.out.println("Probleem: "+u); u.printStackTrace(); } } } } static BufferedReader sisse; static PrintWriter valja; Socket sc; static boolean kas_sees; Frame aken1=new Frame(); Button yhenda=new Button("Ühenda"); Button sulge=new Button("Sulge"); Button paremale=new Button("Paremale"); Button vasakule=new Button("Vasakule"); Button yles=new Button("Yles"); Button alla=new Button("Alla"); public void joonista(String puhver) { Graphics g=aken1.getGraphics(); int mitmes=0; if (puhver.equals("Sinu Voit")) { g.setColor(Color.white); g.drawString(puhver,200,200); } else { for (int u=0;u<20;u++) { for (int i=0;i<20;i++) { int abi; abi=Integer.parseInt(puhver.charAt(mitmes)+""); mitmes++; switch (abi) { case 0: g.setColor(Color.BLACK); break; case 1: g.setColor(Color.BLUE); break; case 2: g.setColor(Color.white); break; case 3: g.setColor(Color.white); break; } if ((i==18) && (u==13)) { g.setColor(Color.red); } g.fillRect(70+i*10,70+u*10,10,10); } } } } public klient() { aken1.setSize(500,500); setLayout(new BorderLayout()); Panel paneel_1=new Panel(new GridLayout(1,6)); paneel_1.add(yhenda); paneel_1.add(sulge); paneel_1.add(paremale); paneel_1.add(vasakule); paneel_1.add(yles); paneel_1.add(alla); yhenda.addActionListener(this); sulge.addActionListener(this); paremale.addActionListener(this); vasakule.addActionListener(this); yles.addActionListener(this); alla.addActionListener(this); aken1.add(paneel_1,BorderLayout.NORTH); klient.kas_sees=false; aken1.setVisible(true); } public void actionPerformed(ActionEvent syndmus) { if (syndmus.getSource()==sulge) { if (klient.kas_sees==true) {System.exit(0);} } if (syndmus.getSource()==yhenda) { if (klient.kas_sees==false) { klient.kas_sees=true; try { sc=new Socket("127.0.0.1", 3001); sisse=new BufferedReader(new InputStreamReader(sc.getInputStream())); valja=new PrintWriter(sc.getOutputStream(), true); new kuulariloim(); } catch(Exception e) { System.out.println("Probleem: "+e); e.printStackTrace(); } } } if (syndmus.getSource()==paremale) {valja.println("p");} if (syndmus.getSource()==vasakule) {valja.println("v");} if (syndmus.getSource()==yles) {valja.println("y");} if (syndmus.getSource()==alla) {valja.println("a");} } public static void main(String argumendid[]) throws Exception { new klient(); } }