×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: abdul qayyum
Added: Aug 13, 2015 12:10 AM
Views: 6
Tags: no tags
File_1
  1. package training1;
  2.  
  3. import java.util.List;
  4. import javafx.beans.Observable;
  5. import javafx.beans.property.IntegerProperty;
  6. import javafx.beans.property.SimpleIntegerProperty;
  7. import javafx.collections.FXCollections;
  8. import javafx.collections.ListChangeListener;
  9. import javafx.collections.ObservableList;
  10. import javafx.util.Callback;
  11.  
  12. public class Training1 {
  13.  
  14.     public static void main(String[] args) {
  15.        
  16.         Callback<Person,Observable[]> cb = (Person p) -> new Observable[]{
  17.             p.firstNameProperty(),
  18.             p.lastNameProperty()
  19.         };
  20.        
  21.         ObservableList<Person> list = FXCollections.observableArrayList(cb);
  22.        
  23.         list.addListener(new PersonListChangeListener());
  24.        
  25.         Person p1 = new Person("Li","Na");
  26.         System.out.println("Before adding "+p1+": "+list+"<--List");
  27.         list.add(p1);
  28.         System.out.println("After Adding "+p1+": "+list);
  29.        
  30.         Person p2 = new Person("Vivi","Gin");
  31.         Person p3 = new Person("Li","He");
  32.         System.out.println("\nBefore adding "+p2+" and "+p3+":"+list+"<--List");
  33.         list.addAll(p2,p3);
  34.         System.out.println("After adding "+p2+" and "+p3+": "+list+"<--List");
  35.        
  36.         System.out.println("\n Before sorting the list"+list+"<--List");
  37.         FXCollections.sort(list);
  38.         System.out.println("After sorting the list"+list+"<--List");
  39.        
  40.         System.out.println("\nBefore updating "+p1+": "+list+"<-- List");
  41.         p1.setLastName("Smith");
  42.         System.out.println("After updating"+p1+":"+list+"<-- List");
  43.        
  44.         Person p = list.get(0);
  45.         Person p4 = new Person("Simon","Ng");
  46.         System.out.println("\nBefore replacing "+p+" with "+list+"<-- List");
  47.         list.set(0, p4);
  48.         System.out.println("After replacing"+p+" with "+p4+": "+list+"<-- List");
  49.        
  50.     }
  51.    
  52. }
  53.    
  54.  
  55.