import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.net.*; import java.io.*; import java.util.*; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.*; import javax.vecmath.*; public class Vorguliiklus3d2 extends Applet implements KeyListener, Runnable{ BufferedReader sisse; PrintWriter valja; String masin="localhost"; int port=3001; String nimi="Jaagup"; TransformGroup keere1; public Vorguliiklus3d2(){ try{ setLayout(new BorderLayout()); Canvas3D c = new Canvas3D( SimpleUniverse.getPreferredConfiguration()); add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); Transform3D keerd1=new Transform3D(); keere1=new TransformGroup(keerd1); keere1.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE); juur.addChild(keere1); keere1.addChild(new ColorCube(0.5)); juur.compile(); SimpleUniverse u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(juur); c.addKeyListener(this); Socket sc=new Socket(masin, port); valja=new PrintWriter(sc.getOutputStream(), true); sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); System.out.println(sisse.readLine()); valja.println(nimi); new Thread(this).start(); }catch(Exception viga){ viga.printStackTrace(); } } public void run(){ while(true){ try{ String rida=sisse.readLine(); StringTokenizer stk=new StringTokenizer(rida); int x=Integer.parseInt(stk.nextToken()); int y=Integer.parseInt(stk.nextToken()); Transform3D t=new Transform3D(); t.setTranslation( new Vector3d((x-100)/10.0, 0, (y-100)/10.0) ); keere1.setTransform(t); String nimi=stk.nextToken(); }catch(Exception viga){ System.out.println(viga); } } } public void keyPressed(KeyEvent e){ int kood=e.getKeyCode(); if(kood==KeyEvent.VK_LEFT){ valja.println(".vasakule"); } if(kood==KeyEvent.VK_RIGHT){ valja.println(".paremale"); } if(kood==KeyEvent.VK_UP){ valja.println(".yles"); } if(kood==KeyEvent.VK_DOWN){ valja.println(".alla"); } } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Klahvikuular"); f.add(new Vorguliiklus3d2()); f.setSize(300, 300); f.setVisible(true); } }