ITI0011:praktikum 11 T8
Tagasi ITI0011 lehele.
Üldine
Praktikum: 11.11.2014 kell 8:00
Koodinäide
Kimp.java:
<source lang="java">
import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Polyline; import javafx.stage.Stage;
public class Kimp extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage primaryStage) throws Exception { BorderPane root = new BorderPane(); Scene scene = new Scene(root, 500, 500);
Pane drawingPane = new Pane(); root.setCenter(drawingPane);
EventHandler<MouseEvent> myHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getEventType() == MouseEvent.MOUSE_PRESSED) { System.out.println("pressed. create a new line, " + "add line to lines list," + "add a point to the line" + event.getX() + ", " + event.getY()); } else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) { System.out.println("dragged. get the last line," + "add point to it:" + event.getX() + ", " + event.getY()); } } };
drawingPane.addEventHandler(MouseEvent.MOUSE_PRESSED, myHandler); drawingPane.addEventHandler(MouseEvent.MOUSE_DRAGGED, myHandler);
primaryStage.setScene(scene); primaryStage.show();
// create a line: Polyline line = new Polyline(); // add line to list drawingPane.getChildren().add(line); // add first point line.getPoints().add(10.0); // x line.getPoints().add(10.0); // y
// drag, add a point //line = last line // getChildren -> arrayList // size().. last element? line.getPoints().add(100.0); // x line.getPoints().add(200.0); // y
// new mouse pressed: line = new Polyline(); line.setStroke(Color.BLUE); // add line to list drawingPane.getChildren().add(line); // add first point line.getPoints().add(159.0); // x line.getPoints().add(88.0); // y
// drag, add a point line.getPoints().add(160.0); // x line.getPoints().add(90.0); // y // drag, add a point line.getPoints().add(162.0); // x line.getPoints().add(91.0); // y }
}
</source>