Thursday, November 19, 2015

JavaFx Tutorial For Beginners 17 - JavaFX Properties

JavaFX Properties









package application;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
 @Override
 public void start(Stage primaryStage) {
  try {
   Parent root = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
   Scene scene = new Scene(root);
   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
   primaryStage.setScene(scene);
   primaryStage.show();
  } catch(Exception e) {
   e.printStackTrace();
  }
 }
 
 public static void main(String[] args) {
  launch(args);
 }
}




package application;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;

public class MainController implements Initializable {
 final MyNumber myNum = new MyNumber();
    
    @FXML
    private Label lblStatus;
 @Override
 public void initialize(URL location, ResourceBundle resources) {
  myNum.setNumber(0);
  myNum.numberProperty().addListener(new ChangeListener<Object>() {

   @Override
   public void changed(ObservableValue<? extends Object> observable,
     Object oldValue, Object newValue) {
    lblStatus.setText(new Double(myNum.getNumber()).toString());
    
   }
  });
  
 }
 
 public void BtnClick(ActionEvent event) {
  myNum.setNumber(myNum.getNumber() + 1);
 }

}




package application;
import javafx.beans.property.*;
public class MyNumber {
 private DoubleProperty number;

 public final double getNumber() {
  if (number != null)
  return number.get();
  return 0;
 }

 public final void setNumber(double number) {
  this.numberProperty().set(number); 
 }
 

 public final DoubleProperty numberProperty() { 
        if (number == null) { 
            number = new SimpleDoubleProperty(0); 
        } 
        return number; 
    } 
}






<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>


<AnchorPane maxWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40" fx:controller="application.MainController">
   <children>
      <Button layoutX="117.0" layoutY="171.0" mnemonicParsing="false" onAction="#BtnClick" prefHeight="63.0" prefWidth="104.0" text="Button" />
      <Label fx:id="lblStatus" layoutX="117.0" layoutY="72.0" prefHeight="52.0" prefWidth="104.0" text="Label" />
   </children>
</AnchorPane>







IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ