0% found this document useful (0 votes)
43 views3 pages

Lab Assignment 9

This document contains the code for a JavaFX application that displays a blue circle and buttons to move the circle. When the program runs it opens a stage with a pane containing the circle and buttons to move the circle left, right, up, down, or reset its position. The buttons trigger code that updates the circle's x and y coordinates to move it on the pane.

Uploaded by

Shivam Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

Lab Assignment 9

This document contains the code for a JavaFX application that displays a blue circle and buttons to move the circle. When the program runs it opens a stage with a pane containing the circle and buttons to move the circle left, right, up, down, or reset its position. The buttons trigger code that updates the circle's x and y coordinates to move it on the pane.

Uploaded by

Shivam Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Assignment 9

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class Arinjay16bit0059 extends Application {

static Circle circle = new Circle();


@Override
@SuppressWarnings("empty-statement")
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
circle.setCenterX(500f);
circle.setCenterY(250f);
circle.setRadius(45.0f);
circle.setFill(javafx.scene.paint.Color.BLUE);
Group root = new Group(circle);
Button mls = new Button("Move Left Side");
Button mrs = new Button("Move Right Side");
Button mt = new Button("Move Top");
Button reset = new Button("Reset");
Button mb = new Button("Move Bottom");

mls.setLayoutX(380);
mls.setLayoutY(500);

mrs.setLayoutX(520);

1
mrs.setLayoutY(500);

mt.setLayoutX(330);
mt.setLayoutY(570);

reset.setLayoutX(500);
reset.setLayoutY(570);

mb.setLayoutX(620);
mb.setLayoutY(570);

Pane r = new Pane();


r.getChildren().addAll(root,mls,mrs,mt,reset,mb);

mls.setOnAction(e -> {
circle.setCenterX(circle.getCenterX()-10);

});
mrs.setOnAction(e -> {
circle.setCenterX(circle.getCenterX()+10);

});
mt.setOnAction(e -> {
circle.setCenterY(circle.getCenterY()-10);

});
reset.setOnAction(e -> {
circle.setCenterX(500f);
circle.setCenterY(250f);

});
mb.setOnAction(e -> {
circle.setCenterY(circle.getCenterY()+10);

2
});

Scene scene = new Scene(r, 1000, 700);


primaryStage.setTitle("Arinjay Jain 16BIT0059");
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {


launch(args);
}
}

You might also like