Use meaningful names; for example, instead of Button b, try Button openButton.
When using detailed comments, keep them up to date; note how meaningful names make some comments superfluous.
Use constants for consistency.
As @jewelsea notes, your program imports java.beans.EventHandler; it should import javafx.event.EventHandler.
As @jewelsea notes, "Only import classes you use."
Let the layout do the work.
I can't explain the error in your question; I see errors related to the incorrect import for EventHandler. If you're using an IDE, it may be reporting errors from a different compilation unit. When in doubt, do a clean build, move the code to a new file, or move to a different development environment, e.g. the command line. As a concrete example, this simple VersionCheck illustrates both a minimal ant script, invoked as ant run, and a simple shell script, invoked as .run.sh:
发布评论
评论(1)
只要注意一些细节,您的代码就可以工作。特别是,尤其是刚开始时,
使用 Java 命名约定.
使用有意义的名称;例如,尝试使用
Button openButton
,而不是Button b
。使用详细注释时,请使其保持最新状态;请注意有意义的名称如何使一些注释变得多余。
使用常量以保持一致性。
正如 @jewelsea 所说,您的程序导入
java.beans.EventHandler
;它应该导入javafx.event.EventHandler
.正如 @jewelsea 所说,“仅导入您使用的类。”
让布局来完成工作。
我无法解释你问题中的错误;我看到与
EventHandler
的import
不正确相关的错误。如果您使用的是 IDE,它可能会报告来自不同编译单元的错误。如有疑问,请进行全新构建,将代码移至新文件,或移至不同的开发环境,例如命令行。作为一个具体的例子,这个简单的 VersionCheck 说明了一个最小的ant
脚本,调用为ant run
,以及一个简单的 shell 脚本,调用为.run.sh
:<前><代码> #!/bin/sh
JFX =“--模块路径/Users/Shared/javafx-sdk-17.0.1/lib --add-modules所有模块路径”
javac $JFX *.java && java $JFX 版本检查
With some attention to detail, your code works. In particular, especially when just starting out,
Use Java naming conventions.
Use meaningful names; for example, instead of
Button b
, tryButton openButton
.When using detailed comments, keep them up to date; note how meaningful names make some comments superfluous.
Use constants for consistency.
As @jewelsea notes, your program imports
java.beans.EventHandler
; it should importjavafx.event.EventHandler
.As @jewelsea notes, "Only import classes you use."
Let the layout do the work.
I can't explain the error in your question; I see errors related to the incorrect
import
forEventHandler
. If you're using an IDE, it may be reporting errors from a different compilation unit. When in doubt, do a clean build, move the code to a new file, or move to a different development environment, e.g. the command line. As a concrete example, this simple VersionCheck illustrates both a minimalant
script, invoked asant run
, and a simple shell script, invoked as.run.sh
: