import javafx.application.*; import javafx.event.*; import javafx.scene.Scene; import javafx.scene.paint.*; import javafx.scene.canvas.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import java.io.*; import java.net.*; import javafx.concurrent.Task; public class GrKlient1 extends Application implements EventHandler, Runnable{ Button nupp1=new Button("Ühendu"); Button nupp2=new Button("Saada"); TextField tfmasin=new TextField(); TextField tfport=new TextField(); TextField tfteade=new TextField(); Label vastus=new Label("vastuse koht"); PrintWriter kirjutaja; BufferedReader lugeja; boolean veel=true; public void handle(ActionEvent e){ try{ if(e.getSource()==nupp1){ Socket sc=new Socket(tfmasin.getText(), Integer.parseInt(tfport.getText())); lugeja=new BufferedReader(new InputStreamReader(sc.getInputStream())); kirjutaja=new PrintWriter(sc.getOutputStream(), true); //Thread t=new Thread(task); //t.setDaemon(true); //t.start(); Platform.runLater(this); } if(e.getSource()==nupp2){ kirjutaja.println(tfteade.getText()); vastus.setText(lugeja.readLine()+"\n"+vastus.getText()); } } catch(Exception ex){ ex.printStackTrace(); } } public void run(){ try{ while(veel){ vastus.setText(lugeja.readLine()+"\n"+vastus.getText()); } }catch(Exception ex){ex.printStackTrace();} } public void start(Stage aken){ GridPane tabel=new GridPane(); tabel.add(tfmasin, 1, 1); tabel.add(tfport, 2, 1); tabel.add(nupp1, 3, 1); tabel.add(tfteade, 1, 2, 2, 1); tabel.add(nupp2, 3, 2); tabel.add(vastus, 1, 3, 2, 1); Scene stseen=new Scene(tabel, 400, 300); nupp1.setOnAction(this); nupp2.setOnAction(this); aken.setScene(stseen); aken.setTitle("Poomismäng"); aken.show(); } public static void main(String[] arg){ launch(arg); } }