忍者ブログ

からすまる日誌

自習 exe3202

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

自習 exe3202

package application;
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.image.Image;
import javafx.scene.paint.Color;
import javafx. stage.Stage;
public class EXE3202 extends Application {
 public static void main(String[] args) {
   launch(args);
 }
 @Override
 public void start(Stage myStage) {
  Canvas canvas = new Canvas(300,300);
  GraphicsContext gc = canvas.getGraphicsContext2D();
  myDraw(gc);
  Image myImg1 = new Image("kobito1.gif");
  canvas.setOnMouseMoved(e ->{
   //gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());;
   gc.drawImage(myImg1, e.getX(), e.getY());
  });
  Group root = new Group();
  root.getChildren().add(canvas);
  Scene scene = new Scene(root, 300, 300, Color.WHITE);
  myStage.setTitle("Exe3202");
  myStage.setScene(scene);
  myStage.show();
 }
 private void myDraw(GraphicsContext gc) {
  //四角
  gc.setFill(Color.GREY);
  gc.fillRect(10,10,50,150);
 }
}
 
clearRectを消せば四角は入る
しかしこびとの軌跡が消えない

PR

コメント

ブログ内検索

カレンダー

04 2025/05 06
S M T W T F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31