我正在制作JavaFX中的屏幕录像机,并且屏幕录像机中必需的一个实用程序是让用户定义要记录的区域.
我设法做了一个未修饰的,半透明的Stage,可以拖动来定义区域并添加一个close按钮让用户确认要记录的区域.
现在,如何通过拖动边缘来让用户调整舞台的大小?
SSCCE:
package draggable;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.SceneBuilder;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBuilder;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPaneBuilder;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class DraggableStage extends Application{
Button close;
StackPane holder;
Rectangle2D maxBounds;
Scene theScene;
double pressedX;
double pressedY;
double draggedX;
double draggedY;
@Override
public void start(Stage stage) throws Exception {
final Stage theStage = stage;
// determine how big …Run Code Online (Sandbox Code Playgroud) 但是在运行时,当我应用第二个场景时,场景不会根据舞台的高度和宽度进行调整.场景的高度和宽度保持不变.
那有什么办法吗?
我试过了
stage.getIcons().add(new Image("attuncore.jpg"));
Run Code Online (Sandbox Code Playgroud)
但我不知道出了什么问题..
请帮忙.提前致谢.
在JavaFX中,如果用户单击某个阶段的关闭按钮(X)(最右上角),我该如何获取该事件?
我希望我的应用程序在窗口关闭时打印调试消息.(System.out.println("Application Close by click to Close Button(X)"))
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
// Any Event Handler
//{
System.out.println("Application(primaryStage) Closed by click to Close Button(X)");
//}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发游戏,需要在我的游戏画面之上使用一些GUI.像FrameLayoutAndroid中的东西.
我有GameScreen,一切都在发生.我现在想要的是添加一个"暂停"按钮,高分信息等.
我试图将一个Stage对象与常规精灵绘图结合起来.但是我在处理输入时遇到了一些问题:如果用户点击阶段中的暂停按钮,或者点击游戏区域(我应该添加一些子弹),如何管理...
有人可以为我清楚吗?
我希望有透明的progressindicator,这是无限期的.
这是代码,它显示灰色背景状态/场景.我希望完全透明.
我尝试了下面的代码,但它显示了不透明的后台阶段.
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Main extends Application {
@Override
public void start(Stage stage) {
/*
*
* my css file content:
*
* .progress-indicator .indicator { -fx-background-color: transparent;
* -fx-background-insets: 0; -fx-background-radius: 0;
*
* } .progress-indicator { -fx-progress-color: green ; }
*
*
*
*/
Stage initStage = new Stage();
initStage.initStyle(StageStyle.TRANSPARENT);
ProgressIndicator loadProgress = new ProgressIndicator();
loadProgress.setSkin(null);
loadProgress.setPrefWidth(50);
VBox box = new …Run Code Online (Sandbox Code Playgroud) 当JavaFX阶段失去它的焦点时,我怎么能运行一段代码(或更确切地说:关闭舞台)?
例如,在Dropbox或Chrome中:如果单击托盘图标,则会打开一个小窗口.如果您现在单击屏幕上的任意位置,窗口将关闭.这正是我想在JavaFX应用程序中创建的行为.
我已经搜索了很长时间才找到解决方案,但找不到一个......
所以,我正在寻找类似这样的东西:
stage.addEventHandler(EventType.FOCUS_LOST, new EventHandler() { /*...*/ } );
Run Code Online (Sandbox Code Playgroud)
谢谢你帮助我!
我想将UI屏幕从更改login.fxml为home.fxml.
我应该改变Stage或Scene?我不确定哪种是最佳做法?另外,我可以在控制器中为处理程序使用lambda表达式吗?
这是我目前在我的Libgdx游戏中的渲染方法.我试图在我的关卡右上角绘制一个BitmapFont,但我得到的只是一堆白盒子.
@Override
public void render(
float delta ) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
this.getBatch().begin();
//myScore.getCurrent() returns a String with the current Score
font.draw(this.getBatch(), "Score: 0" + myScore.getCurrent(), 600, 500);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
this.getBatch().end();
}
Run Code Online (Sandbox Code Playgroud)
我想将得分字体添加到某种演员中,然后做一个scene.addActor(myScore),但我不知道该怎么做.我按照Steigert的教程创建了主要的游戏类,它在AbstractLevel类中实例化了场景,字体,然后由这个级别进行扩展.
到目前为止,我没有使用任何自定义字体,只是空的新BitmapFont(); 用于默认Arial字体.后来我想用我自己更花哨的字体.
我目前正在使用两个控制器类.
在Controller1中,它创建一个在主要阶段之上打开的新阶段.
Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("Controller2.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
Run Code Online (Sandbox Code Playgroud)
现在一旦这个阶段打开,我希望它在关闭之前保持打开约5秒钟.
在Controller2中,我尝试过实现类似的东西
long mTime = System.currentTimeMillis();
long end = mTime + 5000; // 5 seconds
while (System.currentTimeMillis() > end)
{
//close this stage
}
Run Code Online (Sandbox Code Playgroud)
但我不知道在while循环中放入什么来关闭它.我尝试了各种各样的东西,没有任何作用.
stage ×10
java ×7
javafx ×6
javafx-2 ×4
scene ×4
libgdx ×2
android ×1
bitmap-fonts ×1
events ×1
focus ×1
fxml ×1
game-engine ×1
javafx-8 ×1
transparent ×1
while-loop ×1