Compare commits
3 Commits
9b6627566d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f4c20c83e | |||
| eb331f3d22 | |||
| b30611ead5 |
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="project">
|
||||||
|
<words>
|
||||||
|
<w>msksbr</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
Generated
+2
@@ -10,6 +10,8 @@
|
|||||||
<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" />
|
||||||
|
<option value="$PROJECT_DIR$/lesson3" />
|
||||||
</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: 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)
|
||||||
|
}
|
||||||
@@ -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.lesson3.MainKt")
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Lesson: Stage
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.msksbr.jfxLearn.lesson3
|
||||||
|
|
||||||
|
import javafx.application.Application
|
||||||
|
import javafx.scene.Scene
|
||||||
|
import javafx.scene.control.Alert
|
||||||
|
import javafx.scene.control.Button
|
||||||
|
import javafx.scene.control.Label
|
||||||
|
import javafx.scene.image.Image
|
||||||
|
import javafx.scene.input.KeyCode
|
||||||
|
import javafx.scene.input.KeyEvent
|
||||||
|
import javafx.scene.layout.AnchorPane
|
||||||
|
import javafx.scene.layout.BorderPane
|
||||||
|
import javafx.stage.Modality
|
||||||
|
import javafx.stage.Stage
|
||||||
|
import javafx.stage.StageStyle
|
||||||
|
|
||||||
|
class MainApplication : Application() {
|
||||||
|
override fun start(stage: Stage?) {
|
||||||
|
val label = Label("Hello Kotlin\nPress G to view event test dialog")
|
||||||
|
val button0 = Button("APPLICATION MODAL")
|
||||||
|
button0.layoutX = 100.0
|
||||||
|
button0.layoutY = 100.0
|
||||||
|
val button1 = Button("WINDOW MODAL")
|
||||||
|
button1.layoutX = 100.0
|
||||||
|
button1.layoutY = 130.0
|
||||||
|
val button2 = Button("NONE MODAL")
|
||||||
|
button2.layoutX = 100.0
|
||||||
|
button2.layoutY = 160.0
|
||||||
|
val anchorPane = AnchorPane(label, button0, button1, button2)
|
||||||
|
val scene = Scene(anchorPane)
|
||||||
|
|
||||||
|
// modality test window
|
||||||
|
val label0 = Label("stage 0, APPLICATION_MODAL")
|
||||||
|
val borderPane0 = BorderPane(label0)
|
||||||
|
val scene0 = Scene(borderPane0, 300.0, 300.0)
|
||||||
|
val stage0 = Stage()
|
||||||
|
stage0.scene = scene0
|
||||||
|
|
||||||
|
val label1 = Label("stage 1, WINDOW_MODAL")
|
||||||
|
val borderPane1 = BorderPane(label1)
|
||||||
|
val scene1 = Scene(borderPane1, 300.0, 300.0)
|
||||||
|
val stage1 = Stage()
|
||||||
|
stage1.scene = scene1
|
||||||
|
|
||||||
|
val label2 = Label("stage 2, NONE_MODAL")
|
||||||
|
val borderPane2 = BorderPane(label2)
|
||||||
|
val scene2 = Scene(borderPane2, 300.0, 300.0)
|
||||||
|
val stage2 = Stage()
|
||||||
|
stage2.scene = scene2
|
||||||
|
|
||||||
|
// 1, title: set window title
|
||||||
|
stage?.title = "lesson3"
|
||||||
|
// 2, icons: set window icon
|
||||||
|
stage?.icons?.add(Image("mskbot.png"))
|
||||||
|
// 3, isResizable: set window size adjustable
|
||||||
|
stage?.isResizable = false
|
||||||
|
// 4. x, y, width and height
|
||||||
|
// x,y is omitted
|
||||||
|
stage?.width = 300.0
|
||||||
|
stage?.height = 300.0
|
||||||
|
// 5. style:
|
||||||
|
// DECORATED: default on current operating system
|
||||||
|
// UNDECORATED: non-border window
|
||||||
|
// TRANSPARENT: transparent background and non-border, complete transparent, but ONLY THIS STAGE IS TRANSPARENT
|
||||||
|
// UTILITY: only close button and title, just like a dialog
|
||||||
|
stage?.initStyle(StageStyle.DECORATED)
|
||||||
|
// 6. modality
|
||||||
|
// when application modal selected, other stage of this application can't use
|
||||||
|
stage0.initModality(Modality.APPLICATION_MODAL)
|
||||||
|
stage1.initModality(Modality.WINDOW_MODAL)
|
||||||
|
// when window modal selected, it's own stage can't use
|
||||||
|
stage1.initOwner(stage)
|
||||||
|
// default and normal modal option
|
||||||
|
stage2.initModality(Modality.NONE)
|
||||||
|
button0.setOnAction { stage0.show() }
|
||||||
|
button1.setOnAction { stage1.show() }
|
||||||
|
button2.setOnAction { stage2.show() }
|
||||||
|
// 7. event
|
||||||
|
stage?.addEventHandler(KeyEvent.KEY_PRESSED) { event ->
|
||||||
|
if (event.code == KeyCode.G) {
|
||||||
|
Alert(Alert.AlertType.CONFIRMATION).apply {
|
||||||
|
title = "event test"
|
||||||
|
headerText = null
|
||||||
|
contentText = "event test"
|
||||||
|
}.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage?.scene = scene
|
||||||
|
stage?.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
Application.launch(MainApplication::class.java, *args)
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
@@ -1,2 +1,4 @@
|
|||||||
rootProject.name = "jfx-learn"
|
rootProject.name = "jfx-learn"
|
||||||
include("lesson1")
|
include("lesson1")
|
||||||
|
include("lesson2")
|
||||||
|
include("lesson3")
|
||||||
Reference in New Issue
Block a user