gpt4 book ai didi

kotlin - TornadoFX指南:如何实现客户类

转载 作者:行者123 更新时间:2023-12-02 13:37:18 26 4
gpt4 key购买 nike

我从这里开始遵循《 TornadoFX指南》,尝试运行示例向导:
Wizard

并实现了以下附加类Customer,该类未运行:

package com.example.demo.app

import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import java.time.LocalDate
import java.time.Period
import tornadofx.*

class Customer(name: String, zip: Int, city: String, type: String) {
val zipProperty = SimpleIntegerProperty(zip)
var zip by zipProperty

val nameProperty = SimpleStringProperty(name)
var name by nameProperty

val cityProperty = SimpleStringProperty(city)
var city by cityProperty

val typeProperty = SimpleStringProperty(type)
var type by typeProperty

}

我如何按照此处引用的方式添加 Customer.Type,这些类摘自《指南》:
package com.example.demo.view

import com.example.demo.app.Customer
import com.example.demo.app.CustomerModel
import tornadofx.*
class CustomerWizard : Wizard() {
val customer: CustomerModel by inject()

override val canGoNext = currentPageComplete
override val canFinish = allPagesComplete

init {
add(BasicData::class)
add(AddressInput::class)
}
}

class BasicData : View("Basic Data") {
val customer: CustomerModel by inject()

override val complete = customer.valid(customer.name)

override val root = form {
fieldset(title) {
field("Type") {
combobox(customer.type, Customer.Type.values().toList()) //Customer.Type, what is it?
}
field("Name") {
textfield(customer.name).required()
}
}
}
}

class AddressInput : View("Address") {
val customer: CustomerModel by inject()

override val complete = customer.valid(customer.zip, customer.city)

override val root = form {
fieldset(title) {
field("Zip/City") {
textfield(customer.zip) {
prefColumnCount = 5
required()
}
textfield(customer.city).required()
}
}
}
}

错误如下,让我想知道什么是Type?枚举,类,...? Error:(26, 50) Kotlin: Unresolved reference: Type

最佳答案

在上面的示例中,Type是在Customer类内部定义的枚举,例如:

class Customer(name: String, zip: Int, city: String, type: Customer.Type) {
enum class Type {
Private, Company
}

val zipProperty = SimpleIntegerProperty(zip)
var zip by zipProperty

val nameProperty = SimpleStringProperty(name)
var name by nameProperty

val cityProperty = SimpleStringProperty(city)
var city by cityProperty

val typeProperty = SimpleObjectProperty<Type>(type)
var type by typeProperty

}

请注意, typeProperty也已更改为 SimpleObjectProperty<Type>

关于kotlin - TornadoFX指南:如何实现客户类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53479214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com