lesson2
This commit is contained in:
Generated
+1
@@ -10,6 +10,7 @@
|
|||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
<option value="$PROJECT_DIR$/lesson1" />
|
<option value="$PROJECT_DIR$/lesson1" />
|
||||||
|
<option value="$PROJECT_DIR$/lesson2" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
|
|||||||
@@ -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")
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* Lesson: JavaFX Application Structure
|
||||||
|
*
|
||||||
|
* 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
@@ -1,2 +1,3 @@
|
|||||||
rootProject.name = "jfx-learn"
|
rootProject.name = "jfx-learn"
|
||||||
include("lesson1")
|
include("lesson1")
|
||||||
|
include("lesson2")
|
||||||
Reference in New Issue
Block a user