Button_CheckBoxToggle1
  • javafx. scene : Contains a set of base classes of the scene graph hierarchy such as Node, CustomNode, Parent , and so forth and also the Scene class
    that represents the scene graph.
Code : CheckBox

package javafxtemplate1;

import java.sql.SQLException;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.stage.Stage;

public class JavaFXTemplate1 extends Application {

@Override
public void start(Stage primaryStage) {
Group groot = new Group();
CustomEvent ce1 = new CustomEvent();
//annnonymous class
Button btn1 = new Button("Title Button1");
CheckBox chkb1 = new CheckBox("SingleTon");
chkb1.setLayoutX(110);chkb1.setLayoutY(20);
CheckBox chkb2 = new CheckBox("DoubleTon");
chkb2.setLayoutX(190);chkb2.setLayoutY(20);
Button btn2 = new Button("Exit Platform");
btn1.setLayoutX(100);btn1.setLayoutY(80);
Label label1 = new Label("Label");
label1.setLayoutX(90);label1.setLayoutY(40);
//
chkb1.setOnAction((ActionEvent e) -> {
// System.out.println(str1+ "Hello World");
label1.setText("Event Returns : " +
Integer.toString(ce1.Buton_event1(btn1, chkb1, chkb2)));//
primaryStage.setTitle("Radio World");
});
//
chkb2.setOnAction((ActionEvent e) -> {
// System.out.println(str1+ "Hello World");
label1.setText("Event Returns : " +
Integer.toString(ce1.Buton_event2(btn1, chkb1, chkb2)));//
primaryStage.setTitle("Button World");
});
//Class Implementing Event handler
btn2.setOnAction(new DemoEventHandler1(){ });
groot.getChildren().addAll(btn1, label1, btn2, chkb1, chkb2);
Scene scene = new Scene(groot, 350, 150);
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) throws SQLException {
launch(args);
}
class DemoEventHandler1 implements EventHandler<ActionEvent>{

@Override
public void handle(ActionEvent event) {
Platform.exit();

}
}
class CustomEvent{
public int Buton_event1(Button Btn1, CheckBox chkb1,CheckBox chkb2)
{
DropShadow shadow = new DropShadow();
chkb1.setText("Radio ON");
chkb1.setSelected(true);
chkb2.setSelected(false);
Btn1.setText("Changed");
Btn1.setEffect(shadow);
Btn1.setStyle("-fx-font: 22 arial; -fx-base: #b6e7c9;");
int n1 = 15;
return n1;
}
public int Buton_event2(Button Btn1, CheckBox chkb1,CheckBox chkb2)
{
DropShadow shadow = new DropShadow();
chkb1.setText("Radio OFF");
chkb1.setSelected(false);
chkb2.setSelected(true);
Btn1.setText("Title");
Btn1.setEffect(shadow);
Btn1.setStyle("-fx-font: 22 arial; -fx-base: GREEN;");
int n1 = 20;
return n1;
}
}
}

Runtime Views: