Compare commits

...

2 Commits

Author SHA1 Message Date
msksbr eb331f3d22 lesson2 2025-07-26 21:38:51 +08:00
msksbr b30611ead5 lesson2 2025-07-26 21:38:10 +08:00
4 changed files with 82 additions and 1 deletions
+1
View File
@@ -10,6 +10,7 @@
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/lesson1" />
<option value="$PROJECT_DIR$/lesson2" />
</set>
</option>
</GradleProjectSettings>
+23
View File
@@ -0,0 +1,23 @@
plugins {
kotlin("jvm")
}
group = "com.msksbr.jfxLearn"
version = "unspecified"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(17)
}
application.mainClass.set("com.msksbr.jfxLearn.lesson2.MainKt")
+56
View File
@@ -0,0 +1,56 @@
/**
* Lesson: Application
*
* 1. The Application class serves as the entry point for JavaFX applications.
* 2. The main method initiates the JavaFX runtime via Application.launch(String... args).
* 3. When launch() is called without arguments, the application lifecycle follows:
* - init(): Initialization phase
* - start(): Primary stage setup
* - stop(): Cleanup upon application exit
*/
package com.msksbr.jfxLearn.lesson2
import javafx.application.Application
import javafx.scene.Scene
import javafx.stage.Stage
import javafx.scene.control.Button
import javafx.scene.layout.BorderPane
class MainApplication : Application() {
override fun start(stage: Stage) {
println("we are in start method")
// Extension Exercises: create a button, when it clicked, open a website via browser
val button = Button("open website")
button.setOnAction {
hostServices.showDocument("https://msksbr.com")
}
val borderPane = BorderPane(button)
val scene = Scene(borderPane, 300.0, 300.0)
stage.scene = scene
stage.title = "JavaFX Application"
stage.show()
}
override fun init() {
// what can we do in init method?
// 1. connect database
// 2, create a new thread
// ...
println("we are in init method")
}
override fun stop() {
// what can we do in stop method?
// 1. close database connection
// 2. close a thread
// 3. clean resources
// ...
println("we are in stop method")
}
}
fun main(args: Array<String>) {
Application.launch(MainApplication::class.java, *args)
}
+2 -1
View File
@@ -1,2 +1,3 @@
rootProject.name = "jfx-learn"
include("lesson1")
include("lesson1")
include("lesson2")