@Override public void start(Stage primaryStage) throws Exception { BorderPane root = new BorderPane(); HBox message = new HBox(); userText = new TextField(); userText.setEditable(false); userText.setOnAction( e -> { sendMessage(e.getEventType().toString()); userText.setText(""); }); message.getChildren().add(userText); message.setAlignment(Pos.CENTER); message.setPadding(new Insets(10)); chatWindow = new TextArea(); chatWindow.setPrefSize(300, 150); chatWindow.setVisible(true); root.setCenter(chatWindow); root.setBottom(message); startRunning(); primaryStage.setTitle("Instant Messenger"); primaryStage.setScene(new Scene(root, 300, 275)); primaryStage.show(); }
private void initListeners() { txPesquisa.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { if (!txPesquisa.getText().equals("")) { tbVitrine.setItems(findItems()); } else { tbVitrine.setItems(listItens); } } }); tbVitrine .getSelectionModel() .selectedItemProperty() .addListener( new ChangeListener<ItensProperty>() { @Override public void changed( ObservableValue<? extends ItensProperty> value, ItensProperty oldItem, ItensProperty newItem) { ItemApp.produto = new Produto(newItem.getProduto(), newItem.getPreco()); ItemApp.index = tbVitrine.getSelectionModel().getSelectedIndex(); try { new ItemApp().start(new Stage()); } catch (Exception e) { e.printStackTrace(); } } }); }
PortPane() { label = new Label("Willkommen!\n" + "Bitte Port eingeben:"); label.setFont(Font.font("Comic sans MS", 20)); this.add(label, 0, 0, 2, 1); Label portLabel = new Label("Port:"); this.add(portLabel, 0, 1); textField = new TextField("24242"); textField.setPrefColumnCount(5); textField .lengthProperty() .addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { if (newValue.intValue() > 5) textField.setText(textField.getText(0, 5)); else if (newValue.intValue() > oldValue.intValue()) { char ch = textField.getText().charAt(oldValue.intValue()); if (!(ch >= '0' && ch <= '9')) { textField.setText( textField.getText().substring(0, textField.getText().length() - 1)); } } } }); this.add(textField, 1, 1); final Button button = new Button("Fertig!"); HBox hBox = new HBox(10); hBox.getChildren().add(button); hBox.setAlignment(Pos.BOTTOM_RIGHT); this.add(hBox, 1, 2); this.setHgap(10); this.setVgap(10); this.setPadding(new Insets(30, 30, 30, 30)); this.setAlignment(Pos.CENTER); textField.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { button.requestFocus(); } }); button.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { if (!Main.createPortListener(Integer.parseInt(textField.getText()))) { Main.rootPane.setPorteingabe(); setFailure(Integer.parseInt(textField.getText())); } } }); }
@FXML private void handleNameButton() { TextField editNameTextField = nameButtonToTextField(); editNameTextField.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { user.sendMessage(".bye", null); name = editNameTextField.getText().trim(); user = new Client((String) options.get("ip"), Main.PORT, name, null); } }); }
@Override public void initialize(final URL url, final ResourceBundle bundle) { exitItem.setOnAction(e -> Platform.exit()); roomSelection.setItems(FXCollections.observableArrayList("arduino", "java", "groovy", "scala")); roomSelection.getSelectionModel().select(1); model.userName.bindBidirectional(userNameTextfield.textProperty()); model.roomName.bind(roomSelection.getSelectionModel().selectedItemProperty()); model.readyToChat.bind( model.userName.isNotEmpty().and(roomSelection.selectionModelProperty().isNotNull())); chatButton.disableProperty().bind(model.connected.not()); messageTextField.disableProperty().bind(model.connected.not()); messageTextField.textProperty().bindBidirectional(model.currentMessage); connectButton.disableProperty().bind(model.readyToChat.not()); chatListView.setItems(model.chatHistory); messageTextField.setOnAction( event -> { handleSendMessage(); }); chatButton.setOnAction( evt -> { handleSendMessage(); }); connectButton.setOnAction( evt -> { try { clientEndPoint = new ChatClientEndpoint( new URI("ws://quevedo2dam.azurewebsites.net/chat/" + model.roomName.get())); clientEndPoint.addMessageHandler( responseString -> { Platform.runLater( () -> { model.chatHistory.add( jsonMessageToString(responseString, model.roomName.get())); }); }); model.connected.set(true); } catch (Exception e) { showDialog("Error: " + e.getMessage()); } }); aboutMenuItem.setOnAction( event -> { showDialog( "Example websocket chat bot written in JavaFX.\n\n Please feel free to visit my blog at www.hascode.com for the full tutorial!\n\n2014 Micha Kops"); }); }
@Override public void initialize(URL location, ResourceBundle resources) { urlField.setOnAction( event -> { String text = urlField.getText(); urlField.setText("tetetetetetetete"); webView.getEngine().load(text); }); webView .getEngine() .getLoadWorker() .stateProperty() .addListener( (ov, oldState, newState) -> { if (newState == State.SUCCEEDED) { String url = webView.getEngine().getLocation(); urlField.setText(url); if (Pattern.compile("http://item.rakuten.co.jp/.*").matcher(url).find()) { try { Elements tmp; Document document = Jsoup.connect(url).get(); tmp = document.select("input"); tmp = tmp.select("#etime"); if (tmp.size() != 0) { if (!(Long.parseLong(tmp.first().val()) < new Date().getTime())) { entryButton.setDisable(false); } } else { entryButton.setDisable(false); } } catch (Exception e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } } } ; }); entryButton.setOnAction( event -> { urlField.setText("webView disable"); sendEntryTaskController(); }); }
@Override // Override the getPane() method in the super class protected BorderPane getPane() { BorderPane pane = super.getPane(); BorderPane paneForTextField = new BorderPane(); paneForTextField.setPadding(new Insets(5, 5, 5, 5)); paneForTextField.setStyle("-fx-border-color: green"); paneForTextField.setLeft(new Label("Enter a new message: ")); TextField tf = new TextField(); tf.setAlignment(Pos.BOTTOM_RIGHT); tf.setPrefWidth(100); tf.setPrefHeight(100); paneForTextField.setCenter(tf); pane.setTop(paneForTextField); tf.setOnAction(e -> text.setText(tf.getText())); return pane; }
@FXML private void handleJoin() { TextField ipTextField = joinButtonToTextField(); ipTextField.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String ip = ""; if (ipTextField.getText().trim().equals("")) { ip = CLIMain.getLocalAddress(); } else { ip = ipTextField.getText().trim(); } ipTextField.clear(); HashMap options = new HashMap(); // options.put("user", user); options.put("name", name); options.put("ip", ip); new ChatRoomController().changeStage(stage, options); } }); }
@Override public void start(Stage primaryStage) throws Exception { BorderPane pane = FXMLLoader.load(FXMLSample.class.getResource("sample.fxml")); BorderPane browserPane = (BorderPane) pane.getCenter(); final Browser browser = new Browser(); browserPane.setCenter(new BrowserView(browser)); final TextField textField = (TextField) pane.getTop(); textField.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { browser.loadURL(textField.getText()); } }); primaryStage.setTitle("FXMLSample"); primaryStage.setScene(new Scene(pane, 800, 600)); primaryStage.show(); browser.loadURL(textField.getText()); }
@Override public void start(Stage theStage) { this.tStage = theStage; theStage.setTitle("Ball of Duty"); theStage.setHeight(WINDOW_START_HEIGHT); theStage.setWidth(WINDOW_START_WIDTH); theStage.centerOnScreen(); theStage.setResizable(false); theStage.setOnCloseRequest( new EventHandler<WindowEvent>() { public void handle(WindowEvent we) { gameManager.quitGame(); System.exit(0); } }); BorderPane startMenuRoot = new BorderPane(); startMenu = new Scene(startMenuRoot); gameBox = new BorderPane(); Scene gameScene = new Scene(gameBox); BorderPane createAccountRoot = new BorderPane(); BorderPane lohInRoot = new BorderPane(); theStage.setScene(startMenu); gameManager = new GameClient(getRelativeSceneLocation(theStage)); scale = new Scale(); scale.xProperty().bind(gameScene.widthProperty().divide(WINDOW_START_WIDTH)); scale.yProperty().bind(gameScene.heightProperty().divide(WINDOW_START_HEIGHT)); scale.setPivotX(0); scale.setPivotY(0); // gameBox.getTransforms().add(scale); // gameBox.setBackground(null); // TODO scaling theStage .heightProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); // This // only // happens // once // for // some // reason. }); theStage .widthProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); theStage .xProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); theStage .yProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); gameScene .xProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); gameScene .yProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); Image image = new Image("images/frontpage.png"); BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, false); // new BackgroundImage(image, repeatX, repeatY, position, size) BackgroundImage backgroundImage = new BackgroundImage( image, BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize); // new Background(images...) Background background = new Background(backgroundImage); startMenuRoot.setBackground(background); RadioButton chooseBlaster = new RadioButton("Blaster"); RadioButton chooseRoller = new RadioButton("Roller"); RadioButton chooseHeavy = new RadioButton("Heavy"); final ToggleGroup specializationGroup = new ToggleGroup(); chooseBlaster.setToggleGroup(specializationGroup); chooseRoller.setToggleGroup(specializationGroup); chooseHeavy.setToggleGroup(specializationGroup); chooseBlaster.setSelected(true); HBox specializationBox = new HBox(); specializationBox.setSpacing(9); specializationBox.getChildren().add(chooseBlaster); specializationBox.getChildren().add(chooseRoller); specializationBox.getChildren().add(chooseHeavy); Label lblNickname = new Label("Nickname:"); TextField tfNickname = new TextField(); Button loginStart = new Button("Log in"); Button createStart = new Button("Create Account"); theStage.getIcons().add(new Image("images/ball_red.png")); VBox mainButtonBox = new VBox(); mainButtonBox.setSpacing(5); Button joinBtn = new Button("Join game"); Button viewLB = new Button("Leaderboard"); viewLB.setPrefSize(150, 50); viewLB.setId("viewLB"); viewLB.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); BorderPane lbBorder = new BorderPane(); VBox lbBox = new VBox(); Scene lbScene = new Scene(lbBorder); Button lbBack = new Button("Start menu"); lbBox.getChildren().add(lbBack); lbBorder.setLeft(lbBox); lbBack.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); Label topText = new Label("Only shows scores higher than 100!"); topText.setStyle("-fx-font-size: 20pt;-fx-font-family: Segoe UI Semibold;"); viewLB.setOnAction( ActionEvent -> { HighscoreLeaderboard hBoard = gameManager.getHighscoreLeaderboard(); hBoard.setFocusTraversable(false); lbBorder.setCenter(hBoard); if (gameManager.getPlayer() != null) { Player client = gameManager.getPlayer(); Label you = new Label( "YOU: " + client.getNickname() + " [" + client.getId() + "] | Score: " + client.getHighscore()); you.setStyle("-fx-font-size: 15pt;-fx-font-family: Segoe UI Semibold;"); lbBorder.setBottom(you); } BorderPane.setMargin(hBoard, new Insets(12, 12, 12, 12)); lbBorder.setTop(topText); theStage.setScene(lbScene); lbBack.setOnAction( ActionEvent1 -> { theStage.setScene(startMenu); startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); joinBtn.setPrefSize(150, 50); tfNickname.setPrefSize(150, 20); joinBtn.setId("joinBtn"); joinBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblNickname.setId("lblNickname"); lblNickname.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); createStart.setId("CreateStart"); createStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); loginStart.setId("loginStart"); loginStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); joinBtn.setOnAction( ActionEvent -> { Specializations spec; if (chooseRoller.isSelected()) { spec = Specializations.ROLLER; } else if (chooseHeavy.isSelected()) { spec = Specializations.HEAVY; } else // Blaster is default, if something goes wrong with radio // buttons { spec = Specializations.BLASTER; } theStage.setScene(gameScene); gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec); gameManager.getMap().addObserver(this); gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); gameBox.requestFocus(); }); tfNickname.setOnAction( ActionEvent -> { Specializations spec; if (chooseRoller.isSelected()) { spec = Specializations.ROLLER; } else if (chooseHeavy.isSelected()) { spec = Specializations.HEAVY; } else // Blaster is default, if something goes wrong with radio // buttons { spec = Specializations.BLASTER; } theStage.setScene(gameScene); gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec); gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); gameBox.requestFocus(); }); mainButtonBox.getChildren().add(lblNickname); mainButtonBox.getChildren().add(tfNickname); mainButtonBox.getChildren().add(specializationBox); mainButtonBox.getChildren().add(joinBtn); mainButtonBox.getChildren().add(loginStart); mainButtonBox.getChildren().add(createStart); mainButtonBox.getChildren().add(viewLB); startMenuRoot.setLeft(mainButtonBox); createStart.setOnAction( ActionEvent -> { VBox createAccountButtonBox = new VBox(); Label lblNickname2 = new Label("Nickname:"); TextField tfNickname2 = new TextField(); Label lblUserName = new Label("Name:"); TextField tfUserName = new TextField(); Label lblPassword = new Label("Password:"******"Repeat password:"******"Create account"); Button back = new Button("Start menu"); createBtn.setId("join-yyyyy"); createBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblUserName.setId("join-game"); lblUserName.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblPassword.setId("join-game"); lblPassword.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblPassword2.setId("join-game"); lblPassword2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); back.setId("join-game"); back.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); createAccountButtonBox.getChildren().add(lblNickname2); createAccountButtonBox.getChildren().add(tfNickname2); createAccountButtonBox.getChildren().add(lblUserName); createAccountButtonBox.getChildren().add(tfUserName); createAccountButtonBox.getChildren().add(lblPassword); createAccountButtonBox.getChildren().add(pf); createAccountButtonBox.getChildren().add(lblPassword2); createAccountButtonBox.getChildren().add(pf2); createAccountButtonBox.getChildren().add(createBtn); createAccountButtonBox.getChildren().add(back); startMenuRoot.setLeft(createAccountButtonBox); BorderPane.setMargin(createAccountButtonBox, new Insets(350, 0, 0, 150)); createBtn.setOnAction( ActionEvent1 -> { gameManager.createAccount( tfUserName.getText(), tfNickname2.getText(), pf.getText().toCharArray(), pf2.getText().toCharArray()); startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); back.setOnAction( ActionEvent1 -> { startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); loginStart.setOnAction( ActionEvent -> { VBox loginButtonBox = new VBox(); Button logInBtn = new Button("Log in"); Label lblUserName2 = new Label("Name:"); TextField tfUserName2 = new TextField(); Label lblPassword2 = new Label("Password:"******"Start Menu"); logInBtn.setId("join-game"); logInBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); back2.setId("join-game"); back2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); loginButtonBox.getChildren().add(lblUserName2); loginButtonBox.getChildren().add(tfUserName2); loginButtonBox.getChildren().add(lblPassword2); loginButtonBox.getChildren().add(pf3); loginButtonBox.getChildren().add(logInBtn); loginButtonBox.getChildren().add(back2); startMenuRoot.setLeft(loginButtonBox); BorderPane.setMargin(loginButtonBox, new Insets(350, 0, 0, 150)); logInBtn.setOnAction( ActionEvent1 -> { // TODO login }); back2.setOnAction( ActionEvent1 -> { startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); Button quitBtn = new Button("Quit game"); quitBtn.setPrefSize(80, 40); quitBtn.setId("quit-game"); quitBtn.setOnAction( ActionEvent -> { gameManager.quitGame(); theStage.setScene(startMenu); }); canvas = new Canvas(CANVAS_START_WIDTH, CANVAS_START_HEIGHT); gameBox.setCenter(canvas); BorderPane.setAlignment(canvas, Pos.TOP_LEFT); gameBox.setBottom(quitBtn); BorderPane.setAlignment(quitBtn, Pos.TOP_LEFT); theStage.show(); }
@Override public void initialize(URL url, ResourceBundle resourceBundle) { lightfishLocation.setText(this.dashboardModel.getUri()); lightfishLocation.setOnAction(EventHandler -> updateUri()); }
// Override the start() method. public void start(Stage myStage) { // Give the stage a title. myStage.setTitle("Demonstrate a TextField"); // Use a FlowPane for the root node. In this case, // vertical and horizontal gaps of 10. FlowPane rootNode = new FlowPane(10, 10); // Center the controls in the scene. rootNode.setAlignment(Pos.CENTER); // Create a scene. Scene myScene = new Scene(rootNode, 230, 140); // Set the scene on the stage. myStage.setScene(myScene); // Create a label that will report the state of the // selected checkbox. response = new Label("Search String: "); // Create a button that gets the text. Button btnGetText = new Button("Get Search String"); // Create a text field tf = new TextField(); // Set the prompt. tf.setPromptText("Enter Search String"); // Set preferred column count. tf.setPrefColumnCount(15); // Handle action events for the text field. Action // events are generated when ENTER is pressed while // the textfield has input focus. In this case, the // text in the field is obtained and displayed. tf.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent ae) { response.setText("Search String: " + tf.getText()); } }); // Get text from the text field when the button is pressed // and display it. btnGetText.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent ae) { response.setText("Search String: " + tf.getText()); } }); // Use a separator to better organize the layout. Separator separator = new Separator(); separator.setPrefWidth(180); // Add controls to the scene graph. rootNode.getChildren().addAll(tf, btnGetText, separator, response); // Show the stage and its scene. myStage.show(); }