Guest User

Untitled

a guest
Apr 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.45 KB | None | 0 0
  1. import javafx.application.Application
  2. import javafx.scene.control.Button
  3. import javafx.scene.layout.VBox
  4. import tornadofx.*
  5. import java.time.LocalDate
  6. import java.time.Period
  7.  
  8. class Person(id: Int, name: String, birthday: LocalDate) {
  9.     var id by property(id)
  10.     fun idProperty() = getProperty(Person::id)
  11.  
  12.     var name by property(name)
  13.     fun nameProperty() = getProperty(Person::name)
  14.  
  15.     var birthday by property(birthday)
  16.     fun birthdayProperty() = getProperty(Person::birthday)
  17.  
  18.     val age: Int get() = Period.between(birthday, LocalDate.now()).years
  19. }
  20.  
  21.  
  22. private val persons = listOf(
  23.         Person(1,"Samantha Stuart",LocalDate.of(1981,12,4)),
  24.         Person(2,"Tom Marks",LocalDate.of(2001,1,23)),
  25.         Person(3,"Stuart Gills",LocalDate.of(1989,5,23)),
  26.         Person(3,"Nicole Williams",LocalDate.of(1998,8,11))
  27. ).observable()
  28.  
  29. class MyView : View() {
  30.  
  31.     override val root = VBox()
  32.  
  33.     init {
  34.         with(root) {
  35.             Button("Press Me")
  36.             Button("Foo")
  37.             tableview(persons) {
  38.                 isEditable = true
  39.                 column("ID",Person::id).makeEditable()
  40.                 column("Name", Person::name).makeEditable()
  41.                 column("Birthday", Person::birthday).makeEditable()
  42.                 column("Age", Person::age)
  43.             }
  44.  
  45.         }
  46.     }
  47. }
  48.  
  49. class MyApp: App(MyView::class)
  50.  
  51. fun main(args: Array<String>) {
  52.     Application.launch(MyApp::class.java, *args)
  53. }
Advertisement
Add Comment
Please, Sign In to add comment