JAVAFX
JAVAFX
PRACTICAL-17
AIM: Write a program that displays a tic-tac-toe board. A cell may be
X, O, or empty. What to display at each cell is randomly decided.
The X and O are images in the files X.gif and O.gif.
/*
* To change this template, choose Tools | Templates * and open the template in the
editor.
*/
package javafxapplication4;
/**
* @author 576
*/
@Override
for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int n = (int)(Math.random() *
3); if (n == 0)
OUTPUT:
220760116025
PRACTICAL-18
AIM: Write a program that moves a circle up, down, left or right
using arrow keys.
package practical18;
@Override
public void start(Stage primaryStage) { final Pane pane = new Pane(); final Circle
circle = new Circle(30, 30, 30); pane.getChildren().add(circle);
pane.setOnKeyPressed(new
javafx.event.EventHandler<javafx.scene.input.KeyEvent>() {
@Override
});
OUTPUT:
220760116025
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.
/*
* To change this template, choose Tools | Templates * and open the template in the
editor.
*/
package practical19;
@Override
public void start(Stage primaryStage) { final Circle circle = new Circle(50, 50, 20);
circle.setStroke(Color.BLACK);
primaryStage.setScene(scene);
stackPane.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
});
220760116025
stackPane.setOnMouseReleased(new EventHandler<MouseEvent>() {
@Override
});
OUTPUT:
220760116025
PRACTICAL-20
AIM: Write a GUI program that use button to move the message to
the left and right and use the radio button to change the color for the
message displayed.
/*
* To change this template, choose Tools | Templates * and open the template in the
editor.
*/
package practocal20;
@Override
rbBlack.setToggleGroup(group); rbOrange.setToggleGroup(group);
rbGreen.setToggleGroup(group);
pane.setTop(paneForRadioButtons);
btLeft.setOnAction(new EventHandler<ActionEvent>() {
@Override
});
btRight.setOnAction(new EventHandler<ActionEvent>() {
@Override
});
rbRed.setOnAction(new EventHandler<ActionEvent>() {
@Override
});
rbYellow.setOnAction(new EventHandler<ActionEvent>() {
220760116025
@Override
if (rbYellow.isSelected()) { text.setFill(Color.YELLOW);
});
rbBlack.setOnAction(new EventHandler<ActionEvent>() {
@Override
});
rbOrange.setOnAction(new EventHandler<ActionEvent>() {
@Override
});
rbGreen.setOnAction(new EventHandler<ActionEvent>() {
@Override
text.setFill(Color.GREEN);
}
220760116025
});
}
220760116025
OUTPUT: