Button 带有FXML的JavaFX下的全屏显示不起作用
请查看代码片段:Button 带有FXML的JavaFX下的全屏显示不起作用,button,javafx-2,fullscreen,fxml,stage,Button,Javafx 2,Fullscreen,Fxml,Stage,请查看代码片段: import java.io. *; * import java.sql.; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.image.Image; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.util.Resourc
import java.io. *;
* import java.sql.;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.image.Image;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
javafx.animation import *.;
import javafx.animation.PathTransition.OrientationType;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.animation.TranslateTransitionBuilder;
import static javafx.application.Application.launch;
import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.Tooltip;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.CubicCurveTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.PathBuilder;
import javafx.scene.shape.Rectangle;
import javafx.stage.Modality;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
public class Book extends Application implements Initializable
{
@ Override
public void start (Stage primaryStage) throws IOException
{
Stage stage = primaryStage;
Parent root = FXMLLoader.load (getClass () getResource ("Buch.fxml").);
Scene scene = new Scene (root);
stage.setTitle ("book");
stage.setScene (scene);
. stage.getIcons () add (new Image ("icon.png"));
/ / Stage.setFullScreen (true) / / Works
stage.show ();
}
@ FXML
public void fullscreen (ActionEvent event)
{
/ / Stage.setFullScreen (true) / / Does not work
/ / Can not find symbol (stage)
}
如果我不使用FXML,那么它可以工作(:-D):
我的问题是:如何在任何地方使用stage变量?
还是有其他解决办法?
JavaFX很酷,只是遗憾没有一个好的IDE(带有GUI设计器)。
您可以忘记的JavaFX场景生成器和使用FXML是愚蠢的!:-(
但是,我不知道JavaFX场景生成器的替代方案。
没有创建GUI设计器的GUI对于大型程序来说是愚蠢的:-(
请帮帮我
在互联网上我的问题没有答案,这让我很惊讶。(既没有德语教程,也没有英语教程)
对不起,我的英语不好。
我学习这门语言:-)。
我也是Java初学者:-)
我希望我没有忘记任何事情
谢谢:-)在类中声明一个静态阶段变量,并将primaryStage分配给它
public class Book extends Application implements Initializable
{
public static Stage stage;
@ Override
public void start (Stage primaryStage) throws IOException
{
stage = primaryStage;
...
}
...
@ FXML
public void fullscreen (ActionEvent event)
{
stage.setFullScreen(true);
}
}
非常感谢!:-)
public class Book extends Application implements Initializable
{
@ Override
public void start (Stage primaryStage) throws IOException
{
Stage stage = primaryStage;
Parent root = FXMLLoader.load (getClass () getResource ("Buch.fxml").);
Scene scene = new Scene (root);
stage.setTitle ("book");
stage.setScene (scene);
. stage.getIcons () add (new Image ("icon.png"));
stage.show ();
* /
@ FXML
public void fullscreen (ActionEvent event)
{
stage.setFullScreen (true) / / Does not work
/ / Can not find symbol (stage)
}
/ * / / Will not work
}
public class Book extends Application implements Initializable
{
public static Stage stage;
@ Override
public void start (Stage primaryStage) throws IOException
{
stage = primaryStage;
...
}
...
@ FXML
public void fullscreen (ActionEvent event)
{
stage.setFullScreen(true);
}
}