Skip to content

Instantly share code, notes, and snippets.

View PragmaticCoding's full-sized avatar

Dave Barrett PragmaticCoding

View GitHub Profile
private final StringProperty firstName = new SimpleStringProperty("Alloysius");
public String getFirstName() {
return firstName.get();
}
public StringProperty firstNameProperty() {
return firstName;
}
@PragmaticCoding
PragmaticCoding / gist:e7e3c38f85227842558e3ebc79f6c9ff
Last active January 13, 2022 07:09
Kotlin Property Implementation and Assignment
class KotlinClass() {
public var nickName: String = ""
}
fun main(args: Array<String>) {
val testClass = KotlinClass()
testClass.nickName = "Shorty"
println("Nickname: $testclass.nickName")
}
@PragmaticCoding
PragmaticCoding / gist:34b03c5530a07313dca2f4c27b4c5785
Last active January 13, 2022 07:08
Kotlin Property with Overriden Getter and Setter
class KotlinClass() {
public var nickName: String = ""
set(value) {
field = value
println("in the setter")
}
get() {
println("in the getter")
return field
}
@PragmaticCoding
PragmaticCoding / gist:f6d3bd9dfc261b6d411d7945172d5833
Last active January 13, 2022 07:10
JavaFX Property "Bean" Implemented in Kotlin
class KotlinClass() {
private val _nickName: ObjectProperty<String> = SimpleObjectProperty("")
var nickName: String
get() = _nickName.get()
set(value) = _nickName.set(value)
fun nickNameProperty() = _nickName
}
fun main(args: Array<String>) {
@PragmaticCoding
PragmaticCoding / gist:d301cb308d2b4741220c6146cf3ba69c
Last active January 13, 2022 07:11
Intellij Live Template for JavaFX Property Bean
private val _$PROPERTY$: ObjectProperty<$PROPERTY_TYPE$> = SimpleObjectProperty($INIT_VAL$)
var $PROPERTY$: $PROPERTY_TYPE$
get() = _$PROPERTY$.get()
set(value) = _$PROPERTY$.set(value)
fun $PROPERTY$Property() = _$PROPERTY$
@PragmaticCoding
PragmaticCoding / gist:a55821e44ddb909e290a05491bfaad4f
Created November 26, 2021 19:48
Simple Class With 1 Field + Getter + Setter
class Sample {
private int intField = 0;
public int getIntField() {
return intField;
}
public void setIntField(int newValue) {
intField = newValue;
@PragmaticCoding
PragmaticCoding / gist:aee9580aad1e0d3a7347eb742f82ddda
Last active November 26, 2021 20:14
Simple Kotlin Class Showing Getter and Setter Use
class Sample {
var intField: Int = 0
}
fun UseSample() {
val sample = Sample()
sample.setIntField(3)
println(sample.getIntField())
}
class Sample {
var intField: Int = 0
}
fun UseSample() {
val sample = Sample()
sample.inField = 3
println(sample.intField)
}
fun handleNullable() {
val customer: Customer? = database.fetchCustomer(customerId)
val customerName:String = customer?.let{it.getName()}?: "Mr. Nobody"
println("The customer name is $customerName")
}
fun betterHandleNullable() {
println("The customer name is " + database.fetchCustomer(customerId)?.name ?: "Mr. Nobody")
}
hbox.children += ImageView(Image(path.toExternalForm())).apply {
fitHeight = 600.0
isPreserveRatio = true
opacity = 0.7
}