当前位置: 首页>>代码示例>>Java>>正文


Java Scene.setOnKeyPressed方法代码示例

本文整理汇总了Java中javafx.scene.Scene.setOnKeyPressed方法的典型用法代码示例。如果您正苦于以下问题:Java Scene.setOnKeyPressed方法的具体用法?Java Scene.setOnKeyPressed怎么用?Java Scene.setOnKeyPressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.scene.Scene的用法示例。


在下文中一共展示了Scene.setOnKeyPressed方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addKeyHandler

import javafx.scene.Scene; //导入方法依赖的package包/类
private void addKeyHandler(Scene scene) {
    scene.setOnKeyPressed(ke -> {
        KeyCode keyCode = ke.getCode();
        if (keyCode.equals(KeyCode.S)) {
            gameManager.saveSession();
            return;
        }
        if (keyCode.equals(KeyCode.R)) {
            gameManager.restoreSession();
            return;
        }
        if (keyCode.equals(KeyCode.P)) {
            gameManager.pauseGame();
            return;
        }
        if (keyCode.equals(KeyCode.Q) || keyCode.equals(KeyCode.ESCAPE)) {
            gameManager.quitGame();
            return;
        }
        if (keyCode.isArrowKey()) {
            Direction direction = Direction.valueFor(keyCode);
            gameManager.move(direction);
        }
    });
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:26,代码来源:Game2048.java

示例2: NewTaskWindow

import javafx.scene.Scene; //导入方法依赖的package包/类
/**
 * Builds the window and add events.
 * @throws IOException 
 */
public NewTaskWindow() throws IOException {
    super();

    FXMLLoader fxmlLoader = new FXMLLoader(
            getClass().getResource("/FXML/newTask.fxml"));
    Parent root = (Parent) fxmlLoader.load();
    taskController
            = (NewTaskController) fxmlLoader.getController();
    taskController.applyGUIMods();
    
    Scene scene = new Scene(root);
    scene.setFill(javafx.scene.paint.Color.TRANSPARENT);
    setScene(scene);
    setTitle("Add a task");
    setResizable(false);
    initStyle(StageStyle.TRANSPARENT);

    this.wantsToAdd = false;
    //After pressing 'Enter', closes this window (which returns the value)
    scene.setOnKeyPressed((final KeyEvent keyEvent) -> {
        if (keyEvent.getCode() == KeyCode.ENTER) {
            this.wantsToAdd = true;
            this.close();
        } else if (keyEvent.getCode() == KeyCode.ALT) {
            //Using alt key since tab doesn't work
            taskController.showDetails();
        } else if (keyEvent.getCode() == KeyCode.ESCAPE) {
            this.close();
        }
    });

    //Not focusing the window means closing it
    focusedProperty().addListener((obs, wasFocused, isNowFocused) -> {
        if (!isNowFocused) {
            close();
        }
    });
}
 
开发者ID:Soheibooo,项目名称:EMBER,代码行数:43,代码来源:NewTaskWindow.java

示例3: NewTaskListWindow

import javafx.scene.Scene; //导入方法依赖的package包/类
/**
 * Builds the window and add events.
 * @throws IOException 
 */
public NewTaskListWindow() throws IOException {
    super();
    FXMLLoader fxmlLoader = new FXMLLoader(
            getClass().getResource("/FXML/newTaskList.fxml"));
    Parent root = (Parent) fxmlLoader.load();
    taskListController
            = (NewTaskListController) fxmlLoader.getController();

    Scene scene = new Scene(root);
    setScene(scene);
    setResizable(false);
    initStyle(StageStyle.TRANSPARENT);

    this.wantsToAdd = false;
    //After pressing 'Enter', closes this window (which returns the value)
    scene.setOnKeyPressed((final KeyEvent keyEvent) -> {
        if (keyEvent.getCode() == KeyCode.ENTER) {
            this.wantsToAdd = true;
            this.close();
        } else if (keyEvent.getCode() == KeyCode.ESCAPE) {
            this.close();
        }
    });

    //Not focusing the window means closing it
    focusedProperty().addListener((obs, wasFocused, isNowFocused) -> {
        if (!isNowFocused) {
            close();
        }
    });
}
 
开发者ID:Soheibooo,项目名称:EMBER,代码行数:36,代码来源:NewTaskListWindow.java

示例4: ModifyTaskWindow

import javafx.scene.Scene; //导入方法依赖的package包/类
/**
 * Builds the window and add events.
 * @param oldTask Task to use.
 * @throws IOException 
 */
public ModifyTaskWindow(Task oldTask)
        throws IOException {
    super();

    FXMLLoader fxmlLoader = new FXMLLoader(
            getClass().getResource("/fxml/modifyTask.fxml"));
    Parent root = (Parent) fxmlLoader.load();
    taskController
            = (ModifyTaskController) fxmlLoader.getController();
    
    Scene scene = new Scene(root);
    setScene(scene);
    setResizable(false);
    initStyle(StageStyle.TRANSPARENT);
    taskController.fillOldTaskInfos(oldTask);
    
    //After pressing 'Enter', closes this window (which returns the value)
    scene.setOnKeyPressed((final KeyEvent keyEvent) -> {
        if (null != keyEvent.getCode()) switch (keyEvent.getCode()) {
            case ENTER:
                this.wantsToAdd = true;
                this.close();
                break;
            case ESCAPE:
                this.close();
                break;
            default:
                break;
        }
    });

    //Not focusing the window means closing it
    focusedProperty().addListener((obs, wasFocused, isNowFocused) -> {
        if (!isNowFocused) {
            close();
        }
    });
}
 
开发者ID:Soheibooo,项目名称:EMBER,代码行数:44,代码来源:ModifyTaskWindow.java

示例5: start

import javafx.scene.Scene; //导入方法依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
	Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));

	Scene scene = new Scene(root);
	

	stage.setScene(scene);
	stage.getIcons().add(new Image("/icon.png"));
	stage.show();
	stage.setMinWidth(stage.getWidth());
	stage.setMinHeight(stage.getHeight());

	scene.setOnKeyPressed(e -> {
	    if (e.getCode() == KeyCode.NUMPAD1 || e.getCode() == KeyCode.DIGIT1) {
	        controller.keyPressed('1');
	    }else if (e.getCode() == KeyCode.NUMPAD2 || e.getCode() == KeyCode.DIGIT2) {
	        controller.keyPressed('2');
	    }else if (e.getCode() == KeyCode.NUMPAD3 || e.getCode() == KeyCode.DIGIT3) {
	        controller.keyPressed('3');
	    }else if (e.getCode() == KeyCode.NUMPAD4 || e.getCode() == KeyCode.DIGIT4) {
	        controller.keyPressed('4');
	    }else if (e.getCode() == KeyCode.NUMPAD5 || e.getCode() == KeyCode.DIGIT5) {
	        controller.keyPressed('5');
	    }else if (e.getCode() == KeyCode.NUMPAD6 || e.getCode() == KeyCode.DIGIT6) {
	        controller.keyPressed('6');
	    }else if (e.getCode() == KeyCode.NUMPAD7 || e.getCode() == KeyCode.DIGIT7) {
	        controller.keyPressed('7');
	    }else if (e.getCode() == KeyCode.NUMPAD8 || e.getCode() == KeyCode.DIGIT8) {
	        controller.keyPressed('8');
	    }else if (e.getCode() == KeyCode.NUMPAD9 || e.getCode() == KeyCode.DIGIT9) {
	        controller.keyPressed('9');
	    }else if (e.getCode() == KeyCode.NUMPAD0 || e.getCode() == KeyCode.DIGIT0) {
	        controller.keyPressed('0');
	    }else if (e.getCode() == KeyCode.ADD || e.getCode() == KeyCode.PLUS) {
	        controller.keyPressed('+');
	    }else if (e.getCode() == KeyCode.SUBTRACT || e.getCode() == KeyCode.MINUS) {
	        controller.keyPressed('-');
	    }else if (e.getCode() == KeyCode.MULTIPLY) {
	        controller.keyPressed('*');
	    }else if (e.getCode() == KeyCode.DIVIDE || e.getCode() == KeyCode.SLASH) {
	        controller.keyPressed('/');
	    }else if (e.getCode() == KeyCode.ENTER || e.getCode() == KeyCode.EQUALS) {
	        controller.keyPressed('=');
	    }else if (e.getCode() == KeyCode.PERIOD || e.getCode() == KeyCode.COMMA || e.getCode() == KeyCode.DECIMAL) {
	        controller.keyPressed('.');
	    }else if (e.getCode() == KeyCode.BACK_SPACE) {
	        controller.keyPressed('b');
	    }else if (e.getCode() == KeyCode.ESCAPE || e.getCode() == KeyCode.DELETE) {
	        controller.keyPressed('c');
	    }
	});
}
 
开发者ID:kudlav,项目名称:Sifon-Industries,代码行数:54,代码来源:Calc.java

示例6: ModifyTaskListWindow

import javafx.scene.Scene; //导入方法依赖的package包/类
/**
 * Builds the window and add events.
 * @param oldTaskList Task list to use.
 * @throws IOException 
 */
public ModifyTaskListWindow(TaskList oldTaskList)
        throws IOException {
    super();

    FXMLLoader fxmlLoader = new FXMLLoader(
            getClass().getResource("/fxml/modifyTaskList.fxml"));
    Parent root = (Parent) fxmlLoader.load();
    taskListController
            = (ModifyTaskListController) fxmlLoader.getController();
    
    Scene scene = new Scene(root);
    setScene(scene);
    setResizable(false);
    initStyle(StageStyle.TRANSPARENT);
    taskListController.fillOldTaskListInfos(oldTaskList);
    
    //After pressing 'Enter', closes this window (which returns the value)
    scene.setOnKeyPressed((final KeyEvent keyEvent) -> {
        if (null != keyEvent.getCode()) {
            switch (keyEvent.getCode()) {
                case ENTER:
                    ModifyTaskListWindow.this.wantsToAdd = true;
                    ModifyTaskListWindow.this.close();
                    break;
                case ESCAPE:
                    ModifyTaskListWindow.this.close();
                    break;
                default:
                    break;
            }
        }
    });

    //Not focusing the window means closing it
    focusedProperty().addListener((obs, wasFocused, isNowFocused) -> {
        if (!isNowFocused) {
            close();
        }
    });
}
 
开发者ID:Soheibooo,项目名称:EMBER,代码行数:46,代码来源:ModifyTaskListWindow.java

示例7: start

import javafx.scene.Scene; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
	Scene scene = new Scene(initGround());
	scene.setOnKeyPressed(event -> {
			if (event.getCode() == KeyCode.UP){
				if(playGround.nyertes != 1 && playGround.kezdes == 1){
				playGround.Move(Direction.UP);
				updatePlayGround();
				}
			}
		
			if (event.getCode() == KeyCode.DOWN){
				if(playGround.nyertes != 1 && playGround.kezdes == 1){
				playGround.Move(Direction.DOWN);
				updatePlayGround();
				}
			}
			
			if (event.getCode() == KeyCode.LEFT){
				if(playGround.nyertes != 1 && playGround.kezdes == 1){
				playGround.Move(Direction.LEFT);
				updatePlayGround();
				}
			}
			
			if (event.getCode() == KeyCode.RIGHT){
				if(playGround.nyertes != 1 && playGround.kezdes == 1){
				playGround.Move(Direction.RIGHT);
				updatePlayGround();
				}
			}
	});
	
	
       app.getChildren().add(setRightBlock());
       app.getChildren().addAll(setWelcomeScreen());
       
	primaryStage.setScene(scene);
	primaryStage.show();
	
	playGround.getDatum();
	
}
 
开发者ID:kacshuffle,项目名称:SokobanGame,代码行数:44,代码来源:ViewController.java

示例8: start

import javafx.scene.Scene; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
    mediaController.playMusic();
    Scene scene = new Scene(createContent());
    scene.setOnMouseClicked(event -> {
        mediaController.playJumpMusic();
        ship.jump();
    });
    effectPlaying = true;
    scene.setOnKeyPressed(event -> {
        if (event.getCode() == KeyCode.SPACE){
                ship.jump();
                mediaController.playJumpMusic();
                effectPlaying = false;
        }

        if (running && event.getCode() == KeyCode.ESCAPE){
            logger.debug("Game paused.");
            running = false;
            failGame = false;
            viewController.newGame(ship);
            viewController.highScore();
            viewController.optionsMenu();
            mediaController.onSoundButton();
            viewController.addToLeadBoardMenu();
            viewController.resumeMenu();
            viewController.descLabel.setVisible(true);
        }
    });

    primaryStage.setScene(scene);
    primaryStage.show();

    AnimationTimer timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
                update();
        }
    };

    timer.start();
}
 
开发者ID:madar94,项目名称:FlappySpaceShip,代码行数:43,代码来源:Main.java

示例9: show

import javafx.scene.Scene; //导入方法依赖的package包/类
private void show() {
	BorderPane bp = new BorderPane();
	bp.setPadding(new Insets(10,50,50,50));
	HBox hb = new HBox();
	hb.setPadding(new Insets(20,20,20,30));		
	//Implementing Nodes for GridPane
	Label lblUserName = new Label("Username");		
	Label lblPassword = new Label("Password");
	Label lblLanguage = new Label("Language");	

	Button btnReset = createButton("Reset", "btnLogin");
	Button btnRegister = createButton("Register", "btnReset");
	Button btnLogin = createButton("Login", "btnReset");

	//Adding GridPane
	GridPane gridPane = createGridPane(lblUserName, lblPassword, lblLanguage, btnLogin, btnReset, btnRegister);
	gridPane.setId("root");
	Text text = createText("Game Login");
	text.setId("text");
	//Adding text to HBox
	hb.getChildren().add(text);
	//Add ID's to Nodes
	bp.setId("bp");	
	//Add HBox and GridPane layout to BorderPane Layout
	bp.setTop(hb);
	bp.setCenter(gridPane); 				
	//Adding BorderPane to the scene and loading CSS
	scene = new Scene(bp);
	scene.getStylesheets().setAll(CSS_LOCATION);		
	//Action for btnLogin
	btnLogin.setOnAction(e -> buttonLoginAction());
	//Action for btnReset
	btnReset.setOnAction(e -> buttonResetAction());		
	//Action for btnRegister
	btnRegister.setOnAction(p -> {
		tempCheckUser = txtUserName.getText().toString();
		tempCheckPw = pf.getText().toString();
		if(tempCheckUser.length() < LENGTH_OF_USER || tempCheckPw.length() < LENGTH_OF_PASSWORD ){
			MessageShowing unsuccess = new MessageShowing();
			unsuccess.show("failure");
			tempCheckUser="";
			tempCheckPw = "";
			buttonResetAction();
			return;
		}
		usersModel.addUser(tempCheckUser, tempCheckPw);

		writer.write(tempCheckUser, tempCheckPw);
		((PopUpMessage) p).show("success");
		buttonResetAction();});	

	scene.setOnKeyPressed(e -> handleKeyInput(e.getCode()));
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:54,代码来源:PasswordManager.java

示例10: attachEventHandlers

import javafx.scene.Scene; //导入方法依赖的package包/类
public static void attachEventHandlers(Scene s){
    keyReleaseHanlder krh = new keyReleaseHanlder();
    keyPressedHandler kph = new keyPressedHandler();
    s.setOnKeyReleased(krh);
    s.setOnKeyPressed(kph);
}
 
开发者ID:ashish2199,项目名称:Aidos,代码行数:7,代码来源:EventHandler.java


注:本文中的javafx.scene.Scene.setOnKeyPressed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。