import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.control.TextField; import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; import javafx.scene.shape.ArcType; import javafx.stage.Stage; import javafx.scene.input.MouseEvent; import javafx.event.*; public class Joonis5 extends Application implements EventHandler{ GraphicsContext gc; Takisti5 t=new Takisti5(10, 30, 80, 30, 220, 0.5); TextField tf=new TextField("20"); //pinge TextField tf2=new TextField("20"); //takisti raadius int hx1, hy1; public Joonis5(){ t.rakendaPinge(20); tf.setOnAction((event) -> { t.rakendaPinge(Double.parseDouble(tf.getText())); joonista(); }); } public void handle(MouseEvent e){ if(e.getEventType()==MouseEvent.MOUSE_PRESSED){ hx1=(int)e.getX(); hy1=(int)e.getY(); } if(e.getEventType()==MouseEvent.MOUSE_RELEASED){ t.muudaAsukoht(hx1, hy1, (int)e.getX(), (int)e.getY()); joonista(); } if(e.getEventType()==MouseEvent.MOUSE_DRAGGED){ t.muudaAsukoht(hx1, hy1, (int)e.getX(), (int)e.getY()); joonista(); } if(e.getEventType()==MouseEvent.MOUSE_MOVED){ t.muudaTekstiNahtavus((int)e.getX(), (int)e.getY()); joonista(); } } public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { stage.setTitle("Joonistusaken"); Group root = new Group(); Canvas canvas = new Canvas(300, 250); gc = canvas.getGraphicsContext2D(); joonista(); root.getChildren().add(canvas); HBox paneel1=new HBox(); paneel1.getChildren().addAll(tf, tf2); root.getChildren().add(paneel1); stage.setScene(new Scene(root)); stage.show(); canvas.setOnMousePressed(this); canvas.setOnMouseReleased(this); canvas.setOnMouseDragged(this); canvas.setOnMouseMoved(this); } private void joonista() { gc.setFill(Color.WHITE); gc.fillRect(0, 0, 300, 250); gc.setFill(Color.BLACK); t.joonista(gc); } }