Code:
Class:: Emp1
public class Emp1 {
//
private final StringProperty firstName;
private final StringProperty lastName ;
private final DoubleProperty Salary;
public Emp1(String firstName, String lastName, Double salary) {
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
this.Salary = new SimpleDoubleProperty(salary);
}
//
public double getSalary(){
return Salary.get();
}
public void setSalary(Double Salary){
this.Salary.set(Salary);
}
public DoubleProperty salaryproperty()
{
return Salary;
}
//
public String getFirstName() {
return firstName.get();
}
//
public void setFirstName(String firstName) {
this.firstName.set(firstName);
}
public StringProperty firstNameProperty() {
return firstName;
}
public String getLastName() {
return lastName.get();
}
public void setLastName(String lastName) {
this.lastName.set(lastName);
}
public StringProperty lastNameProperty() {
return lastName;
}
@Override
public String toString() {
return (getFirstName() + " " + getLastName() + " " + getSalary());
}
}
|
Code :
package javafxtemplate1;
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
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.Label;
import javafx.stage.Stage;
/**
*
* @author Manas9
*/
public class JavaFXTemplate1 extends Application {
public String str1;
@Override
public void start(Stage primaryStage) {
Group groot = new Group();
Label label1 = new Label("Caption");
Emp1 emp1 = new Emp1("John", "Doe", 2500.45);
label1.setLayoutX(120);label1.setLayoutY(20);
Button btn1 = new Button("click Me");
btn1.setOnAction((ActionEvent event) -> {
IntegerProperty counter = new SimpleIntegerProperty(1);
int n1 = counter.get();
// label1.setText("OOOOOOPS " + Integer.toString(n1));
label1.setText(emp1.toString());
});
groot.getChildren().addAll(label1, btn1);
Scene scene = new Scene(groot, 350, 150);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
}
|