Skip to content

Commit

Permalink
Merge branch 'main' of github.com:worldline/learning-kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
yostane committed Dec 3, 2024
2 parents 6b3341e + eabc4e0 commit f29a568
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 0 deletions.
25 changes: 25 additions & 0 deletions jbang-catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"catalogs": {},
"aliases": {
"jfxapp": {
"script-ref": "material/scripting/jbang/jfxdemo.kt",
"description": "Single file JavaFX application that defined the UI with code (no fxml)"
}
},
"templates": {
"jfxkt-legacy": {
"file-refs": {
"{basename}.kt": "material/scripting/jbang/jfxdemo.kt"
},
"description": "Single file JavaFX application",
"properties": {}
},
"jfxkt": {
"file-refs": {
"{basename}.kt": "material/scripting/jbang/jfxdemo.qute"
},
"description": "Single file JavaFX application that defined the UI with code (no fxml)",
"properties": {}
}
}
}
1 change: 1 addition & 0 deletions material/scripting/jbang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
44 changes: 44 additions & 0 deletions material/scripting/jbang/jfxdemo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
///usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS org.openjfx:javafx-controls:23
//DEPS org.openjfx:javafx-graphics:23:${os.detected.jfxname}
//DEPS org.openjfx:javafx-fxml:23

import javafx.application.Application
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.stage.Stage

class HelloJFXApp : Application() {
private var scene: Scene? = null

override fun start(stage: Stage) {
val javaInfoString = String.format(
"Java: %s, %s , %s",
System.getProperty("java.version"),
System.getProperty("java.vendor"),
System.getProperty("java.vm.version")
)
val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version"))

val holder = VBox()
holder.isFillWidth = true
holder.alignment = Pos.TOP_CENTER
holder.spacing = 5.0
holder.children.addAll(
Label(javaInfoString),
Label(jfxInfoString),
)

scene = Scene(holder, 400.0, 300.0)
stage.title = "JavaFX Demo"
stage.scene = scene
stage.show()
}
}

fun main() {
Application.launch(HelloJFXApp::class.java)
}
44 changes: 44 additions & 0 deletions material/scripting/jbang/jfxdemo.qute
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
///usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS org.openjfx:javafx-controls:23
//DEPS org.openjfx:javafx-graphics:23:${os.detected.jfxname}
//DEPS org.openjfx:javafx-fxml:23

import javafx.application.Application
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.stage.Stage

class {baseName} : Application() {
private var scene: Scene? = null

override fun start(stage: Stage) {
val javaInfoString = String.format(
"Java: %s, %s , %s",
System.getProperty("java.version"),
System.getProperty("java.vendor"),
System.getProperty("java.vm.version")
)
val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version"))

val holder = VBox()
holder.isFillWidth = true
holder.alignment = Pos.TOP_CENTER
holder.spacing = 5.0
holder.children.addAll(
Label(javaInfoString),
Label(jfxInfoString),
)

scene = Scene(holder, 400.0, 300.0)
stage.title = "JavaFX Demo"
stage.scene = scene
stage.show()
}
}

fun main() {
Application.launch(HelloJFXApp::class.java)
}
44 changes: 44 additions & 0 deletions material/scripting/jbang/testjfx.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
///usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS org.openjfx:javafx-controls:23
//DEPS org.openjfx:javafx-graphics:23:${os.detected.jfxname}
//DEPS org.openjfx:javafx-fxml:23

import javafx.application.Application
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.stage.Stage

class HelloJFXApp : Application() {
private var scene: Scene? = null

override fun start(stage: Stage) {
val javaInfoString = String.format(
"Java: %s, %s , %s",
System.getProperty("java.version"),
System.getProperty("java.vendor"),
System.getProperty("java.vm.version")
)
val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version"))

val holder = VBox()
holder.isFillWidth = true
holder.alignment = Pos.TOP_CENTER
holder.spacing = 5.0
holder.children.addAll(
Label(javaInfoString),
Label(jfxInfoString),
)

scene = Scene(holder, 400.0, 300.0)
stage.title = "JavaFX Demo"
stage.scene = scene
stage.show()
}
}

fun main() {
Application.launch(HelloJFXApp::class.java)
}
44 changes: 44 additions & 0 deletions material/scripting/jbang/testjfx2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
///usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS org.openjfx:javafx-controls:23
//DEPS org.openjfx:javafx-graphics:23:$NOT_FOUND
//DEPS org.openjfx:javafx-fxml:23

import javafx.application.Application
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.stage.Stage

class testjfx2 : Application() {
private var scene: Scene? = null

override fun start(stage: Stage) {
val javaInfoString = String.format(
"Java: %s, %s , %s",
System.getProperty("java.version"),
System.getProperty("java.vendor"),
System.getProperty("java.vm.version")
)
val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version"))

val holder = VBox()
holder.isFillWidth = true
holder.alignment = Pos.TOP_CENTER
holder.spacing = 5.0
holder.children.addAll(
Label(javaInfoString),
Label(jfxInfoString),
)

scene = Scene(holder, 400.0, 300.0)
stage.title = "JavaFX Demo"
stage.scene = scene
stage.show()
}
}

fun main() {
Application.launch(HelloJFXApp::class.java)
}
1 change: 1 addition & 0 deletions material/scripting/kts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
18 changes: 18 additions & 0 deletions material/scripting/kts/compiler-options.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@file:CompilerOptions("-jvm-target", "1.8", "-Xabi-stability=unstable")

interface Test {
fun print()
fun printSuper() = println("Hi from super")
}

class TestImpl : Test {
override fun print() = println("Hi from sub")
}

fun printRandom() = println("Hi from random")

TestImpl().run {
print()
printSuper()
printRandom()
}
40 changes: 40 additions & 0 deletions material/scripting/kts/jfxdemo.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@file:DependsOn("org.openjfx:javafx-controls:23")
@file:DependsOn("org.openjfx:javafx-graphics:23")

import javafx.application.Application
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.stage.Stage


class HelloJFXApp : Application() {
private var scene: Scene? = null

override fun start(stage: Stage) {
val javaInfoString = String.format(
"Java: %s, %s , %s",
System.getProperty("java.version"),
System.getProperty("java.vendor"),
System.getProperty("java.vm.version")
)
val jfxInfoString = String.format("JavaFX: %s", System.getProperty("javafx.version"))

val holder = VBox()
holder.isFillWidth = true
holder.alignment = Pos.TOP_CENTER
holder.spacing = 5.0
holder.children.addAll(
Label(javaInfoString),
Label(jfxInfoString),
)

scene = Scene(holder, 400.0, 300.0)
stage.title = "JavaFX Demo"
stage.scene = scene
stage.show()
}
}

Application.launch(HelloJFXApp::class.java)
Empty file.

0 comments on commit f29a568

Please sign in to comment.