下面列出了javafx.scene.Scene#setOnKeyReleased ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(appRoot);
scene.setOnKeyPressed(event -> keys.put(event.getCode(), true));
scene.setOnKeyReleased(event -> keys.put(event.getCode(), false));
primaryStage.setTitle("Tutorial 14 Platformer");
primaryStage.setScene(scene);
primaryStage.show();
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
update();
}
};
timer.start();
}
@Inject
public LogStage(LogPane logPane, LogListView logView, List<Image> logos, StylesConfig styles) {
BorderPane containerPane = new BorderPane();
containerPane.getStyleClass().addAll(Style.CONTAINER.css());
containerPane.setCenter(logPane);
containerPane.setBottom(new ClosePane((a) -> eventStudio().broadcast(HideStageRequest.INSTANCE, "LogStage")));
Scene scene = new Scene(containerPane);
scene.getStylesheets().addAll(styles.styles());
scene.setOnKeyReleased(k -> {
if (this.isShowing() && new KeyCodeCombination(KeyCode.ESCAPE).match(k)) {
eventStudio().broadcast(HideStageRequest.INSTANCE, "LogStage");
}
});
setScene(scene);
setTitle(DefaultI18nContext.getInstance().i18n("Log register"));
getIcons().addAll(logos);
setMaximized(true);
eventStudio().addAnnotatedListeners(this);
this.onShowingProperty().addListener((o, oldVal, newVal) -> logView.scrollToBottomIfShowing());
eventStudio().add(logView, LOGSTAGE_EVENTSTATION);
}
@Override
public void start(Stage primaryStage) {
try {
primaryStage.setTitle("MCA Selector " + FileHelper.getManifestAttributes().getValue("Application-Version"));
} catch (IOException ex) {
primaryStage.setTitle("MCA Selector - dev");
}
primaryStage.getIcons().add(FileHelper.getIconFromResources("img/icon"));
TileMap tileMap = new TileMap(this, width, height);
BorderPane pane = new BorderPane();
//menu bar
OptionBar optionBar = new OptionBar(tileMap, primaryStage);
pane.setTop(optionBar);
//tilemap
TileMapBox tileMapBox = new TileMapBox(tileMap, primaryStage);
pane.setCenter(tileMapBox);
//status bar
pane.setBottom(new StatusBar(tileMap));
Scene scene = new Scene(pane, width, height);
URL cssRes = Window.class.getClassLoader().getResource("style.css");
if (cssRes != null) {
String styleSheet = cssRes.toExternalForm();
scene.getStylesheets().add(styleSheet);
}
scene.setOnKeyPressed(e -> pressedKeys.add(e.getCode()));
scene.setOnKeyReleased(e -> pressedKeys.remove(e.getCode()));
primaryStage.setOnCloseRequest(e -> System.exit(0));
primaryStage.setScene(scene);
primaryStage.show();
}
public void initialize() {
preInit = false;
rootElement = new VBox();
Scene scene = stage.getScene();
scene.setRoot(rootElement);
FXUtil.runWhenVisible(rootElement, new Runnable() {
@Override
public void run() {
canvasView = new ADCCanvasView();
mainMenuBar = new ADCMenuBar();
rootElement.getChildren().addAll(mainMenuBar, canvasView);
//force canvas to render at proper size
autoResizeCanvasView();
}
});
EventHandler<KeyEvent> keyEvent = new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
canvasView.keyEvent(event.getText(), event.getEventType() == KeyEvent.KEY_PRESSED, event.isShiftDown(), event.isControlDown(), event.isAltDown());
}
};
scene.setOnKeyPressed(keyEvent);
scene.setOnKeyReleased(keyEvent);
scene.getMnemonics().clear();
}
@Override
public void start(Stage stage) throws Exception {
Scene scene = new Scene(createContent());
scene.setOnKeyReleased(e -> {
if (e.getCode() == KeyCode.ENTER) {
saveScreenshot(scene);
}
});
stage.setScene(scene);
stage.show();
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(createContent());
scene.setOnKeyPressed(event -> {
switch (event.getCode()) {
case A:
action = UserAction.LEFT;
break;
case D:
action = UserAction.RIGHT;
break;
}
});
scene.setOnKeyReleased(event -> {
switch (event.getCode()) {
case A:
action = UserAction.NONE;
break;
case D:
action = UserAction.NONE;
break;
}
});
primaryStage.setTitle("Tutorial");
primaryStage.setScene(scene);
primaryStage.show();
startGame();
}
@Override
public void start(Stage primaryStage) throws Exception {
initContent();
Scene scene = new Scene(appRoot);
scene.setOnKeyPressed(event -> keys.put(event.getCode(), true));
scene.setOnKeyReleased(event -> keys.put(event.getCode(), false));
primaryStage.setTitle("Tutorial 14 Platformer");
primaryStage.setScene(scene);
primaryStage.show();
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
if (running) {
update();
}
if (dialogEvent) {
dialogEvent = false;
keys.keySet().forEach(key -> keys.put(key, false));
GameDialog dialog = new GameDialog();
dialog.setOnCloseRequest(event -> {
if (dialog.isCorrect()) {
System.out.println("Correct");
}
else {
System.out.println("Wrong");
}
running = true;
});
dialog.open();
}
}
};
timer.start();
}
@Inject
public InfoStage(InfoPane infoPane, List<Image> logos, StylesConfig styles) {
BorderPane containerPane = new BorderPane();
containerPane.getStyleClass().addAll(Style.CONTAINER.css());
containerPane.setCenter(infoPane);
containerPane.setBottom(new ClosePane());
Scene scene = new Scene(containerPane);
scene.getStylesheets().addAll(styles.styles());
scene.setOnKeyReleased(new HideOnEscapeHandler(this));
setScene(scene);
setTitle(DefaultI18nContext.getInstance().i18n("Document details"));
getIcons().addAll(logos);
setMaximized(true);
}
@Inject
public OpenWithDialog(StylesConfig styles, List<Module> modules) {
initModality(Modality.WINDOW_MODAL);
initStyle(StageStyle.UTILITY);
setResizable(false);
setTitle(DefaultI18nContext.getInstance().i18n("Open with"));
this.modules = modules.stream().sorted(comparing(m -> m.descriptor().getName())).collect(toList());
messageTitle.getStyleClass().add("-pdfsam-open-with-dialog-title");
BorderPane containerPane = new BorderPane();
containerPane.getStyleClass().addAll(Style.CONTAINER.css());
containerPane.getStyleClass().addAll("-pdfsam-open-with-dialog", "-pdfsam-open-with-container");
containerPane.setTop(messageTitle);
BorderPane.setAlignment(messageTitle, Pos.TOP_CENTER);
filesList.setPrefHeight(150);
containerPane.setCenter(filesList);
buttons.getStyleClass().addAll(Style.CONTAINER.css());
containerPane.setBottom(buttons);
BorderPane.setAlignment(buttons, Pos.CENTER);
Scene scene = new Scene(containerPane);
scene.getStylesheets().addAll(styles.styles());
scene.setOnKeyReleased(new HideOnEscapeHandler(this));
setScene(scene);
eventStudio().addAnnotatedListeners(this);
}
public static void attachEventHandlers(Scene s){
keyReleaseHanlder krh = new keyReleaseHanlder();
keyPressedHandler kph = new keyPressedHandler();
s.setOnKeyReleased(krh);
s.setOnKeyPressed(kph);
}
/**
* Register window-level keybinds.
*
* @param controller
* Controller to call actions on.
* @param stage
* Window to register keys on.
* @param scene
* Scene in the window.
*/
public void registerWindowKeys(GuiController controller, Stage stage, Scene scene) {
scene.setOnKeyReleased(e -> handleWindowKeyEvents(e, controller, stage, false));
}
/**
* Register window-level keybinds.
*
* @param controller
* Controller to call actions on.
* @param stage
* Window to register keys on.
* @param scene
* Scene in the window.
*/
public void registerMainWindowKeys(GuiController controller, Stage stage, Scene scene) {
scene.setOnKeyReleased(e -> handleWindowKeyEvents(e, controller, stage, true));
}