/* * GameClient.java * @author Kristof Friedrichsen * @author Ryan Mann * @author Bob Free * @author Pat O'Neill * @version December 15, 2006 **/ package chutesladder; import java.awt.BorderLayout; import java.awt.Event; import java.awt.TextArea; import java.awt.TextField; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import javax.swing.JFrame; public class GameClient extends JFrame implements Runnable{ public static String Ghost = "moxie.oswego.edu"; public static Integer Gport = 2698; static protected BufferedReader Gin; static protected PrintWriter Gout; static protected TextArea Goutput; static protected TextField Ginput; protected Thread Glistener; public GameClient (String title, InputStream Giin, OutputStream Giout) { super (title); this.Gin = new BufferedReader (new InputStreamReader (Giin)); this.Gout = new PrintWriter ( new OutputStreamWriter(Giout)); setLayout (new BorderLayout ()); add ( "Center", Goutput = new TextArea (null,10,60) ); Goutput.setEditable (false); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); add ( "South", Ginput = new TextField () ); pack (); setVisible (true); Ginput.requestFocus (); Glistener = new Thread (this); Glistener.start(); } public void run () { try { while (true) { String line = Gin.readLine (); Goutput.append (line + "\n"); System.out.println("Test line"+line); //CaL.setParseLocation(line); } } catch (IOException ex) { ex.printStackTrace (); } finally { Glistener = null; Ginput.setVisible (false); validate (); Gout.close (); } } public boolean handleEvent (Event e) { if ((e.target == Ginput) && (e.id == Event.ACTION_EVENT)) { Gout.println ((String) e.arg); Gout.flush (); Ginput.setText (""); return true; } else if ((e.target == this) && (e.id == Event.WINDOW_DESTROY)) { if (Glistener != null) Glistener.stop (); setVisible (false); return true; } return super.handleEvent (e); } static public void sendUpdateServer(String up){ Gout.println(up); System.out.println("Test up"+up); Ginput.setText (""); } }