@Override public void start(Stage primaryStage) throws Exception { GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setVgap(10); grid.setHgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); Scene sc = new Scene(grid, 500, 500); String css = Main.class.getResource("Login.css").toExternalForm(); // System.out.println(css); sc.getStylesheets().add(css); Text scenetitle = new Text("Welcome"); // scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 1, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); TextField userTextField = new TextField("Мудак"); grid.add(userTextField, 1, 1); Label pw = new Label("Password:"******"Sign in"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); grid.add(hbBtn, 1, 4); final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6); btn.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { // actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Pressed"); } }); // grid.setGridLinesVisible(true); scenetitle.setId("welc"); actiontarget.setId("act"); primaryStage.setScene(sc); primaryStage.setTitle("Hello World"); primaryStage.show(); }
@Override public void initialize(URL location, ResourceBundle resources) { // TODO 自動生成されたメソッド・スタブ addOption.setOnAction( event -> { for (int i = 0; i < cmb.size(); i++) { // System.out.println(cmb.get(i).getValue()); if (cmb.get(i).getValue() == null) { break; } else if (i == cmb.size() - 1) { addTask.setDisable(false); } } }); addTask.setOnAction( event -> { try { String url = webView.getEngine().getLocation(); System.out.println(url); Document document = Jsoup.connect(url).get(); Elements input = document.select("input"); Map params = new HashMap<String, String>(); for (ComboBox cmbx : cmb) { ValuePair vp = (ValuePair) cmbx.getValue(); params.put(vp.getName(), vp.getvalue()); } // System.out.println(input.select("[name=shop_bid]").first()); // System.out.println(input.select("[name=shop_bid]").first().val()); params.put("shop_bid", input.select("[name=shop_bid]").first().val()); params.put("item_id", input.select("[name=item_id]").first().val()); params.put("__event", input.select("[name=__event]").first().val()); params.put("units", "1"); Map map = new HashMap<String, Long>(); // System.out.println(document.select("#stime").size()); if (document.select("#stime").size() != 0) { System.out.println(document.select("#stime")); map.put("stime", Long.parseLong((input.select("#stime").first().val()))); map.put("etime", Long.parseLong((input.select("#etime").first().val()))); } else { map = null; } BuyTask task = new BuyTask(url, params, map); task.call(); this.getScene().getWindow().hide(); } catch (Exception e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } }); }
public void start(Stage stage) { Button button = new Button("Click me!"); button.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Thanks for clicking!"); } }); stage.setScene(new Scene(button)); stage.show(); }
private void activateRightSideButtons() { colorPyrpur.setOnAction( (me) -> { ((MeshModel) rnaSequence3D.getModels().get(1)).colorPyrPur(); }); colorAugc.setOnAction( (me) -> { ((MeshModel) rnaSequence3D.getModels().get(1)).colorBases(); }); centerObject.setOnAction( (me) -> { tertiaryRoom.setCameraCenter(rnaSequence3D.computeCenter()); }); }
/** Initializer */ protected void init() { mFossilUpgradesPane = new FossilUpgradePane(mModel); EventHandler<ActionEvent> upgradeEvent = new PanelChangeEvent(mFossilUpgradesPane); mFossilUpgrades = new ImageButton("fossilfuelupgrade.png", upgradeEvent); mApply = new Button("Apply"); EventHandler<ActionEvent> applyEvent = new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { mModel .getEnergyManager() .getFossil() .setAmount(Integer.parseInt(mValues.get("Plants in Operation").getText())); } }; EventHandler<ActionEvent> upEvent = new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { mValues .get("Plants in Operation") .setText("" + (Integer.parseInt(mValues.get("Plants in Operation").getText()) + 1)); } }; EventHandler<ActionEvent> downEvent = new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { if (Integer.parseInt(mValues.get("Plants in Operation").getText()) != 0) { mValues .get("Plants in Operation") .setText( "" + (Integer.parseInt(mValues.get("Plants in Operation").getText()) - 1)); } } }; mApply.setOnAction(applyEvent); mUp = new ImageButton("up.png", upEvent); mDown = new ImageButton("down.png", downEvent); mUp.setPrefSize(0, 0); mDown.setPrefSize(0, 0); setHalignment(mDown, HPos.CENTER); setHalignment(mUp, HPos.CENTER); setHalignment(mApply, HPos.CENTER); setHalignment(mFossilUpgrades, HPos.RIGHT); }
@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 public void start(Stage primaryStage) { try { TabPane page = (TabPane) FXMLLoader.load(Main.class.getResource("simple.fxml")); Scene scene = new Scene(page); primaryStage.setScene(scene); primaryStage.setTitle("Hotels"); primaryStage.show(); textf = (TextField) scene.lookup("#HotelNameTextb"); Button create = (Button) scene.lookup("#CreateButton"); create.setOnAction(this::handleButtonAction); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
protected void init() { mActionButton = new Button("Apply"); mActionButton.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { mModel.getUpgradeManager().addLobby(mLobby.getChange()); mModel.getResourceManager().spendActionPoints(Math.abs(mLobby.getChange())); mModel.getUpgradeManager().addOilDrilling(mOil.getChange()); mModel.getResourceManager().spendActionPoints(Math.abs(mOil.getChange())); mModel.getUpgradeManager().addPriceChange(mPrice.getChange()); mModel.getResourceManager().spendActionPoints(Math.abs(mPrice.getChange())); mLobby.saveChanges(); mOil.saveChanges(); mPrice.saveChanges(); update(); } }); setHalignment(mActionButton, HPos.LEFT); }
public static void setJar(final Tile node) { node.data.put("type", "Jar"); List<Node> toRemove = new ArrayList<>(); for (Node n : node.node.getChildren()) { if (!n.getId().equals("delete")) { if (n.getId().equals("typeLabel")) { Label l = (Label) n; l.setText("jar"); l.setTranslateY(l.getTranslateY() - 1); } else { toRemove.add(n); } } } VBox leftPadding = new VBox(); leftPadding.setPrefWidth(14); VBox buttons = new VBox(); VBox textBoxes = new VBox(); VBox extra = new VBox(); buttons.setSpacing(5); textBoxes.setSpacing(5); extra.setSpacing(5); buttons.setPadding(new Insets(7, 0, 0, 0)); textBoxes.setPadding(new Insets(7, 0, 0, 0)); extra.setPadding(new Insets(7, 0, 0, 0)); textBoxes.setTranslateX(17); extra.setTranslateX(32); node.node.getChildren().removeAll(toRemove); final String name = "Package Name"; final String name2 = "Jar Name"; Button findPkg = new Button(); final TextField pkgText = new TextField(); final TextField jarName = new TextField(); findPkg.getStyleClass().add("defaultButton"); findPkg.setText("Find Package Name"); findPkg.setPrefHeight(25); findPkg.setTranslateX(12); findPkg.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String mainClassName = Util.packageNameFromTile(); if (mainClassName != null) { pkgText.setText(mainClassName); } } }); pkgText.setText(name); pkgText.setPrefSize(150, 27); pkgText.setFont(Font.font("Segoe UI")); pkgText.setId("textBox"); pkgText .textProperty() .addListener( new ChangeListener<String>() { @Override public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { node.data.put("package", pkgText.getText().trim()); } }); pkgText .focusedProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue == true && pkgText.getText().equals(name)) { pkgText.setText(""); } else if (newValue == false && pkgText.getText().trim().equals("")) { pkgText.setText(name); } } }); jarName.setText(name2); jarName.setPrefSize(150, 27); jarName.setFont(Font.font("Segoe UI")); jarName.setId("textBox"); jarName .textProperty() .addListener( new ChangeListener<String>() { @Override public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { node.data.put("jarname", jarName.getText().trim()); } }); jarName .focusedProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue == true && jarName.getText().equals(name2)) { jarName.setText(""); } else if (newValue == false && jarName.getText().trim().equals("")) { jarName.setText(name2); } } }); final String defTxt = "Additional Flags"; final TextField flags = new TextField(); flags.setText(defTxt); flags.setPrefSize(150, 27); flags.setFont(Font.font("Segoe UI")); flags.setId("textBox"); flags .focusedProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue == true && flags.getText().equals(defTxt)) { flags.setText(""); } else if (newValue == false && flags.getText().trim().equals("")) { flags.setText(defTxt); } } }); flags .textProperty() .addListener( new ChangeListener<String>() { @Override public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { node.data.put("flags", flags.getText().trim()); } }); final String defTxt2 = "Output Directory"; final TextField outputDir = new TextField(); outputDir.setText(defTxt2); outputDir.setPrefSize(150, 27); outputDir.setFont(Font.font("Segoe UI")); outputDir.setId("textBox"); outputDir .focusedProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue == true && outputDir.getText().equals(defTxt2)) { outputDir.setText(""); } else if (newValue == false && outputDir.getText().trim().equals("")) { outputDir.setText(defTxt2); } } }); outputDir .textProperty() .addListener( new ChangeListener<String>() { @Override public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { node.data.put("output", outputDir.getText().trim()); } }); buttons.getChildren().addAll(findPkg); textBoxes.getChildren().addAll(pkgText, jarName); extra.getChildren().addAll(flags, outputDir); node.node.getChildren().addAll(leftPadding, buttons, textBoxes, extra); }
@Override public void start(Stage primaryStage) { VBox loginPane = new VBox(); loginPane.setAlignment(Pos.CENTER); primaryStage.setTitle("Amoeba"); primaryStage.setScene(new Scene(loginPane, 800, 600)); primaryStage.show(); TextField username = new TextField(); username.setPromptText("Username"); username.setMaxSize(200, 50); Timeline renderTimer = new Timeline(); Timeline inputTimer = new Timeline(); ColorPicker colorPicker = new ColorPicker(); colorPicker.setEditable(true); colorPicker.setValue(Color.BLACK); lagLabel.setTranslateX(25); lagLabel.setTranslateY(10); lagLabel.setTextFill(Color.RED); TextField address = new TextField("localhost"); address.setPromptText("Server IP Address"); address.setMaxSize(200, 50); TextField port = new TextField("8080"); port.setPromptText("Port Number"); port.setMaxSize(200, 50); Button btn = new Button("Play"); btn.setDefaultButton(true); loginPane.getChildren().addAll(username, colorPicker, address, port, btn); primaryStage.setResizable(false); music.setCycleCount(MediaPlayer.INDEFINITE); renderPane.setBackground(new Background(backgroundImage)); renderPane.setPrefSize(800, 600); chatBox.setPrefSize(400, 100); chatBox.setTranslateX(0); chatBox.setTranslateY(468); chatBox.setWrapText(true); chatBox.setEditable(false); chatBox.setStyle("-fx-opacity: 0.5"); chatInput.setPrefSize(400, 10); chatInput.setTranslateX(0); chatInput.setTranslateY(570); chatInput.setStyle("-fx-opacity: 0.8"); highScores.setPrefSize(400, 210); highScores.setEditable(false); currentScores.setPrefSize(400, 250); currentScores.setEditable(false); currentScores.setLayoutY(210); scores.setTranslateX(-390); scores.setTranslateY(0); scores.setStyle("-fx-opacity: 0.8"); scores.setOnMouseEntered( (e) -> { scores.setTranslateX(0); }); scores.setOnMouseExited( (e) -> { if (e.getX() > 350) { scores.setTranslateX(-390); } }); btn.setOnAction( (e) -> { if (!networkController.isConnected()) { networkController.connect(address.getText(), Integer.parseInt(port.getText())); if (username.getText().isEmpty()) { username.setText("Anonymous"); } networkController.sendMessage(new LoginMessage(username.getText(), "")); ArrayList<KeyValuePair> properties = new ArrayList<>(); properties.add(new KeyValuePair("color", colorPicker.getValue().toString())); networkController.sendMessage(new SetBlobPropertiesMessage(properties)); primaryStage.setScene(new Scene(renderPane)); renderTimer.play(); inputTimer.play(); music.play(); } }); inputTimer.setCycleCount(Timeline.INDEFINITE); inputTimer .getKeyFrames() .add( new KeyFrame( Duration.seconds(0.05), (e) -> { if (sendCoordinates) { networkController.sendMessage(new MoveTowardCoordinatesMessage(x, y)); } })); renderTimer.setCycleCount(Timeline.INDEFINITE); renderTimer .getKeyFrames() .add( new KeyFrame( Duration.seconds(0.01), (e) -> { render(); })); renderPane.setOnMouseReleased( (e) -> { this.sendCoordinates = false; }); renderPane.setOnMouseDragged( (e) -> { this.sendCoordinates = true; this.x = e.getX(); this.y = e.getY(); }); renderPane.setOnMouseClicked( (e) -> { if (e.getButton() == MouseButton.SECONDARY) { networkController.sendMessage(new BoostMessage()); } else if (e.getClickCount() > 1 || e.getButton() == MouseButton.MIDDLE) { networkController.sendMessage(new SplitMessage()); } }); renderPane.setOnKeyPressed( (e) -> { if (e.getCode().equals(KeyCode.ENTER) && !chatInput.getText().isEmpty()) { networkController.sendMessage(new ChatMessage("", chatInput.getText())); chatInput.clear(); } }); primaryStage.setOnCloseRequest( (e) -> { networkController.sendMessage(new LogoutMessage()); try { Thread.sleep(100); } catch (InterruptedException ex) { Logger.getLogger(AmoebaClient.class.getName()).log(Level.WARNING, null, ex); } finally { System.exit(0); } }); }
/** * Here is our whole stage with layout, </Br > ( Grid, TextField and Buttons) * * @author PatrikWebb */ public void NameDisplay() { Stage nameWindow = new Stage(); // Block events to other windows nameWindow.initModality(Modality.APPLICATION_MODAL); nameWindow.setTitle("Enter your name"); nameWindow.setMinWidth(250); // GridPane Form GridPane grid = new GridPane(); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(8); grid.setHgap(10); // Name Label Label nameLabel = new Label("Player Name:"); GridPane.setConstraints(nameLabel, 0, 0); // Name Input nameInput = new TextField(); nameInput.setPromptText("Name"); nameInput.setFocusTraversable(false); GridPane.setConstraints(nameInput, 1, 0); // Betting Label Label bettingLabel = new Label("Betting amount: "); GridPane.setConstraints(bettingLabel, 0, 1); // Bett Input playerCashInput = new TextField(); playerCashInput.setFocusTraversable(false); playerCashInput.setPromptText("Betting amount"); GridPane.setConstraints(playerCashInput, 1, 1); // Enter button Button enterButton = new Button("Enter"); enterButton.setFocusTraversable(false); // setPercentWidth(50); GridPane.setConstraints(enterButton, 1, 2); // Cancel button Button cancelButton = new Button("Demo Player"); cancelButton.setFocusTraversable(false); GridPane.setConstraints(cancelButton, 2, 2); // enterButton.setOnAction( e -> { Platform.runLater( () -> { // Get the input from the nameInput TextField name = nameInput.getText(); // Get the betting input from the bettsInput TextField playerCash = Integer.parseInt(playerCashInput.getText()); // Add name and playerCash input to a new player Bank.getInstance().addPlayerToBank(name, playerCash); // Add the player to the table Bank.getInstance().addPlayersToTheTable(); // Close the stage nameWindow.close(); System.out.println("\nPlayer Name: " + name); System.out.println("Betting Amount: " + playerCash + "\n"); }); }); cancelButton.setOnAction( e -> { // TODO Platform.runLater( () -> { /* * * * * * * * * * * * * * If you press cancel you still want a player to join * the table so I add a test player insted of * getting the error, Exception JavaFX Application THREAD ;) * * * * * * * * * * * * */ Bank.getInstance().addPlayerToBank("Demo Player", 500); // Add the player to the table Bank.getInstance().addPlayersToTheTable(); nameWindow.close(); }); }); // Add everything to grid grid.getChildren() .addAll(nameLabel, nameInput, bettingLabel, playerCashInput, enterButton, cancelButton); // Display window and wait for it to be closed before returning Scene scene = new Scene(grid, 450, 150); nameWindow.setScene(scene); nameWindow.showAndWait(); }