當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。