JavaFX StringProperty create

Description

JavaFX StringProperty create

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ReadOnlyProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Main {
  public static void main(String[] args) {
    Language lang = new Language("Java examples", 49, "demo2s.com");

    printDetails(lang.titleProperty());/* ww  w  .  j  a v  a 2  s .  c  o  m*/
    printDetails(lang.priceProperty());
    printDetails(lang.siteProperty());

    lang.setTitle("java tutorial");
    lang.setId(59);

    System.out.println("\nAfter changing the Book properties...");

    // Print Property details
    printDetails(lang.titleProperty());
    printDetails(lang.priceProperty());
    printDetails(lang.siteProperty());
  }

  public static void printDetails(ReadOnlyProperty<?> p) {
    String name = p.getName();
    Object value = p.getValue();
    Object bean = p.getBean();
    String beanClassName = (bean == null) ? "null" : bean.getClass().getSimpleName();
    String propClassName = p.getClass().getSimpleName();

    System.out.print(propClassName);
    System.out.print("[Name:" + name);
    System.out.print(", Bean Class:" + beanClassName);
    System.out.println(", Value:" + value + "]");
  }
}

class Language {
  private StringProperty title = new SimpleStringProperty(this, "title", "Unknown");
  private DoubleProperty id = new SimpleDoubleProperty(this, "price", 0.0);
  private ReadOnlyStringWrapper site = new ReadOnlyStringWrapper(this, "SITE", "Unknown");

  public Language() {
  }

  public Language(String title, double id, String ISBN) {
    this.title.set(title);
    this.id.set(id);
    this.site.set(ISBN);
  }

  public final String getTitle() {
    return title.get();
  }

  public final void setTitle(String title) {
    this.title.set(title);
  }

  public final StringProperty titleProperty() {
    return title;
  }

  public final double getId() {
    return id.get();
  }

  public final void setId(double i) {
    this.id.set(i);
  }

  public final DoubleProperty priceProperty() {
    return id;
  }

  public final String getSite() {
    return site.get();
  }

  public final ReadOnlyStringProperty siteProperty() {
    return site.getReadOnlyProperty();
  }
}



PreviousNext

Related