JavaFX_LifeCycle2
  • Intro to dialogue
  • Alert alert = new Alert(AlertType.INFORMATION);
    alert.setTitle("Information Dialog :: " + str4);
 
Code:

package javafxtemplate1;
//
//textProperty().addListener Listview Label
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
//import javafx.scene.layout.Group;


/**
*
* @author Manas9
*/
public class JavaFXTemplate1 extends Application {
//Group group1,group2;// = new Group();
Pane pane1,pane2; String str1, str2, str3, str4 ;
Button btn1, btn2;
Stage thisstage; Label label1 = new Label();
Label label2 = new Label();Label label3 = new Label();
public JavaFXTemplate1(){
str3 = new String();
str3 = Thread.currentThread().getName();
label3.setText("Constructor "+ str3);
}
@Override
public void init(){
str1 = new String();
str1 = (Thread.currentThread().getName());
label1.setText("Init Pahase " + str1) ;

//start pahse following init would over-write the text
label2.setText("Init Pahase") ;
}
@Override
public void stop(){
str4 = (Thread.currentThread().getName());
System.out.println(str4);
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information Dialog :: " + str4);
alert.setHeaderText("Life Cycle of Java Fx");
alert.setContentText("This ends the application!");
alert.showAndWait();
}
@Override
public void start(Stage primaryStage) throws Exception {
str2 = new String();
str2 = (Thread.currentThread().getName());
label2.setText("start Pahase " +str2) ;
thisstage= primaryStage;
pane1 = new Pane();pane2 = new Pane();
btn1 = new Button("Pane11");
btn2= new Button("Pane2");
btn1.setLayoutX(10); btn1.setLayoutY(10);
btn2.setLayoutX(100); btn2.setLayoutY(10);
label1.setLayoutX(180); label1.setLayoutY(30);
label2.setLayoutX(180); label2.setLayoutY(50);
label3.setLayoutX(180); label3.setLayoutY(0);
//
btn1.setOnAction(e->ctrlbutton1_click());
btn2.setOnAction(e->ctrlbutton2_click());

//
pane1.getChildren().addAll(label1,label2,label3, btn1,btn2);
//canvas2.getChildren().addAll(btn1,btn2);
Scene scene = new Scene(pane1, 300, 150);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFx ::LifeCycle");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
public void ctrlbutton1_click()
{
//System.out.println("setOnAction event :: button Clicked");
//caption.setText("Button Clicked");
pane1.setStyle("-fx-background-color: green;");
}
public void ctrlbutton2_click()
{
//System.out.println("setOnAction event :: button Clicked");
//caption.setText("Button Clicked");
pane1.setStyle("-fx-background-color: red;");
}
}

/*
Convert using Integer.toString(int)
Convert using String.valueOf(int)
Convert using new Integer(int).toString()
Convert using String.format()
canvas.setStyle("-fx-background-color: black;");

*/

 

Displays:]

Now close the above window, an alert screen would prompt