我正在用 Javafx 编写一个非常简单的应用程序,其中舞台上有一个带有文本框的按钮作为一个场景。现在,我想要的行为是,当我单击该按钮时,我可以使用另一个按钮和一个文本框加载另一个场景在舞台上并删除我单击的按钮以及上一个文本框。所以点击一个按钮应该在舞台上加载一个新场景。关于我如何做到这一点的任何提示?
遵循 Eric 的建议:我有这个代码,它的工作方式是我想要的。
var showScene1 = true;
var showScene2 = false;
var showScene3 = false;
def stage = Stage
{
title: "Hello World"
var scene1 =Scene
{
content:
[
Text {
font : Font {
size: 24
}
x: 10, y: 30
content: "HelloWorld from Scene1"
},
Button
{
text: "Click Me to change to Scene2 "
onMouseClicked: function( e: MouseEvent ):Void
{
showScene2 = true;
println("In scene 2");
}
}
]
}
var scene2 =Scene
{
content:
[
Text {
font : Font {
size: 24
}
x: 10, y: 30
content: "HelloWorld from Scene2"
},
Button
{
text: "Click Me to change to Scene3 "
onMouseClicked: function( e: MouseEvent ):Void
{
showScene1 = false;
showScene2 = false;
showScene3 = true;
println("In scene 3");
}
}
]
}
var scene3 =Scene
{
content:
[
Text {
font : Font {
size: 24
}
x: 10, y: 30
content: "HelloWorld from Scene3"
}
]
}
scene: bind if (showScene2) then scene2
else if (showScene1) then scene1
else scene3
}