import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.net.*; import java.io.*; public class Tripsulaud extends Applet implements MouseListener{ String symbolid="_________"; int ruuduLaius; int ruuduKorgus; public Tripsulaud(){ addMouseListener(this); } void loeSymbolid(){ try{ BufferedReader vorgust=new BufferedReader(new InputStreamReader( new URL(getCodeBase(), "kysiSymbolid").openStream() )); symbolid=vorgust.readLine(); vorgust.close(); }catch(Exception ex){ ex.printStackTrace(); } } void joonistaSymbol(Graphics g, int nr){ int rida=nr/3; int veerg=nr%3; if(symbolid.charAt(nr)=='0'){ g.drawOval(veerg*ruuduLaius, rida*ruuduKorgus, ruuduLaius, ruuduKorgus); } if(symbolid.charAt(nr)=='X'){ g.drawLine(veerg*ruuduLaius, rida*ruuduKorgus, veerg*ruuduLaius+ruuduLaius, rida*ruuduKorgus+ruuduKorgus); g.drawLine(veerg*ruuduLaius, rida*ruuduKorgus+ruuduKorgus, veerg*ruuduLaius+ruuduLaius, rida*ruuduKorgus); } } public void mousePressed(MouseEvent e){ int reanr=e.getY()/ruuduKorgus; int veerunr=e.getX()/ruuduLaius; int ruudunr=reanr*3+veerunr; System.out.println(reanr+" "+veerunr+" "+ruudunr); try{ BufferedReader vorgust=new BufferedReader(new InputStreamReader( new URL(getCodeBase(), "vajutus?koht="+ruudunr).openStream() )); String abi=vorgust.readLine(); System.out.println(abi); vorgust.close(); }catch(Exception ex){ ex.printStackTrace(); } repaint(); } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void paint(Graphics g){ loeSymbolid(); ruuduLaius=getWidth()/3; ruuduKorgus=getHeight()/3; g.drawLine(0, ruuduKorgus, 3*ruuduLaius, ruuduKorgus); g.drawLine(0, 2*ruuduKorgus, 3*ruuduLaius, 2*ruuduKorgus); g.drawLine(ruuduLaius, 0, ruuduLaius, 3*ruuduKorgus); g.drawLine(2*ruuduLaius, 0, 2*ruuduLaius, 3*ruuduKorgus); for(int nr=0; nr<9; nr++){ joonistaSymbol(g, nr); } } }