OOP-JAVA Practical 19

OOP-JAVA Practical 19
  • Aim: Write a program that displays the color of a circle as red when the mouse button is pressed and as blue when the mouse button is released.
  • Code:
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.stage.Stage;
    public class practical19 extends Application {
        @Override
        public void start(Stage primaryStage) {
            double width = 250;
            double height = 250;
            Circle c = new Circle(width / 2, height / 2, Math.min(width, height) / 10,
                    Color.BLUE);
            c.setStroke(Color.WHITE);
            StackPane pane = new StackPane(c);
            primaryStage.setScene(new Scene(pane, width, height));
            pane.setOnMousePressed(e -> c.setFill(Color.RED));
            pane.setOnMouseReleased(e -> c.setFill(Color.BLUE));
            primaryStage.setTitle("Practical19");
            primaryStage.show();
        }
    
        public static void main(String[] args) {
            Application.launch(args);
        }
    }
  • Output:
    Output of practical 19

Comments