import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; import javafx.scene.shape.ArcType; import javafx.stage.Stage; import javafx.scene.input.MouseEvent; import javafx.event.*; public class Joonis4 extends Application implements EventHandler{ GraphicsContext gc; int hx1, hy1; 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); stage.setScene(new Scene(root)); stage.show(); canvas.setOnMousePressed(this); canvas.setOnMouseReleased(this); canvas.setOnMouseDragged(this); canvas.setOnMouseMoved(this); } Takisti4 t=new Takisti4(10, 30, 80, 30, 220); private void joonista() { gc.setFill(Color.WHITE); gc.fillRect(0, 0, 300, 250); gc.setFill(Color.BLACK); t.joonista(gc); } }