アットウィキロゴ

にやはっぽー

package pic;
 
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.shape.*;
import static javafx.application.Application.launch;
import javafx.scene.paint.Color;
 import javafx.scene.input.MouseEvent;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.PixelReader;
 import javafx.scene.canvas.GraphicsContext;
 
public class pro extends Application {
 
Canvas cam;
GraphicsContext gc;
 
public static void main(String[] args) {
launch(args);
}
 
 
@Override
public void start(Stage primaryStage) {
 
Image im = new Image("file:ren.jpg");
 
ImageView imageView = new ImageView();
imageView.setImage(im);
 
 
PixelReader reader = im.getPixelReader();
 
cam = new Canvas(700,700);
gc = cam.getGraphicsContext2D();
 
gc.drawImage(im, 0,0);  
 
 
Button btn1 = new Button();
        btn1.setText("左");
        btn1.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
 
                System.out.println("hello");
 
 
            }
        });
 
 
 
cam.addEventHandler(MouseEvent.MOUSE_CLICKED, 
       new EventHandler<MouseEvent>() {
           @Override
           public void handle(MouseEvent e) {
 
  int px=(int)e.getX();
 int py=(int)e.getY();
 
gc.setFill(Color.RED);
gc.fillRect(px,py,5,5);
 
 
}
});
 
 
Group root = new Group();
Scene scene = new Scene(root, 700, 700); 
 
root.getChildren().add(cam);
root.getChildren().add(btn1);
primaryStage.setTitle("グラフ");
primaryStage.setScene(scene);
primaryStage.show();
 
}
 
 
 
}
最終更新:2015年11月19日 21:02