本文整理匯總了Java中javafx.scene.control.Button類的典型用法代碼示例。如果您正苦於以下問題:Java Button類的具體用法?Java Button怎麽用?Java Button使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Button類屬於javafx.scene.control包,在下文中一共展示了Button類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createPresetButtons
import javafx.scene.control.Button; //導入依賴的package包/類
private List<Button> createPresetButtons() {
List<Button> buttons = new ArrayList<>();
for (String gameName : presetGames.keySet()) {
GameMetaData gameMeta = presetGames.get(gameName);
Button button = new Button();
ImageView gameImageView = new ImageView(gameMeta.getImage());
gameImageView.setFitWidth(App.WIDTH / 3);
gameImageView.setPreserveRatio(true);
button.setGraphic(gameImageView);
button.setOnMouseClicked((e) -> {
startGame(gameMeta.getGameFilePath());
});
getRotation(button);
buttons.add(button);
}
return buttons;
}
示例2: addUpgradeBtn
import javafx.scene.control.Button; //導入依賴的package包/類
public void addUpgradeBtn() {
upgradeBtn = new Button();
upgradeBtn.setText("UPGRADE");
upgradeBtn.setOnAction(e -> {
Stage msgStage = new Stage();
VBox root = new VBox();
Scene scene = new Scene(root);
Text text = new Text("Are you sure you want to upgrade " + name + "? It will cost you 10 gold.");
HBox options = new HBox();
Button yes = new Button ("yes");
yes.setOnAction(f -> {
sprite.getComponent(GameBus.TYPE).get().getGameBus().emit(new ChangeWealthEvent
(ChangeWealthEvent.CHANGE, sprite.getComponent(Owner.TYPE).get().player(), WealthType.GOLD, -10));
msgStage.close();
});
Button no = new Button("no");
no.setOnAction(g -> {
msgStage.close();
});
options.getChildren().add(yes);
root.getChildren().addAll(text, options);
msgStage.setScene(scene);
msgStage.show();
});
this.getChildren().add(upgradeBtn);
}
示例3: createComponents
import javafx.scene.control.Button; //導入依賴的package包/類
@Override
@FXThread
protected void createComponents() {
super.createComponents();
resourceLabel = new Label(NOT_SELECTED);
final Button changeButton = new Button();
changeButton.setGraphic(new ImageView(Icons.ADD_16));
changeButton.setOnAction(event -> processSelect());
final HBox container = new HBox(resourceLabel, changeButton);
container.prefWidthProperty().bind(widthProperty().multiply(DEFAULT_FIELD_W_PERCENT));
resourceLabel.prefWidthProperty().bind(container.widthProperty());
FXUtils.addToPane(container, this);
FXUtils.addClassesTo(container, CSSClasses.DEF_HBOX, CSSClasses.TEXT_INPUT_CONTAINER);
FXUtils.addClassesTo(changeButton, CSSClasses.FLAT_BUTTON, CSSClasses.INPUT_CONTROL_TOOLBAR_BUTTON);
FXUtils.addClassTo(resourceLabel, CSSClasses.ABSTRACT_PARAM_CONTROL_ELEMENT_LABEL);
DynamicIconSupport.addSupport(changeButton);
}
示例4: addIntegrationButtonsToVbox
import javafx.scene.control.Button; //導入依賴的package包/類
private void addIntegrationButtonsToVbox(Integration integration, VBox vbox)
{
for (String buttonKey : integration.getActions().keySet())
{
System.out.println("*" + buttonKey);
final Action clickableButton = integration.getActions().get(buttonKey);
if (clickableButton.isHiddenFromFrontend())
{
continue;
}
final Button jfxButton = new Button(clickableButton.getName());
jfxButton.setPadding(new Insets(2, 4, 2, 4));
jfxButton.setMinWidth(256);
jfxButton.setMaxWidth(256);
jfxButton.setAlignment(Pos.BASELINE_LEFT);
jfxButton.setContentDisplay(ContentDisplay.RIGHT);
jfxButton.setTooltip(new Tooltip(buttonKey + "\n" + clickableButton.getDescription())); // I tried it, but it looks a bit janky
jfxButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent arg0)
{
try
{
triggerEvent("<" + clickableButton.getName() + "> from frontend", null);
clickableButton.onAction(null);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
vbox.getChildren().add(jfxButton);
}
}
示例5: makeInputBox
import javafx.scene.control.Button; //導入依賴的package包/類
private VBox makeInputBox() {
VBox inputBox = new VBox(10);
Label username = new Label(USERNAME_LABEL);
Label messageName = new Label(MESSAGE_LABEL);
TextField userField = new TextField();
TextField inputField = new TextField();
Button sendButton = new Button("Send");
sendButton.setOnAction(e -> {
String message = inputField.getText();
String sender = userField.getText();
//FIXME: fix connection stuff
myUser.recieveMessage(sender, message);
});
HBox usernameField = new HBox();
usernameField.getChildren().addAll(username, userField);
HBox messageField = new HBox();
messageField.getChildren().addAll(messageName, inputField);
inputBox.getChildren().addAll(usernameField, messageField, sendButton);
return inputBox;
}
示例6: makeReturnHomeButton
import javafx.scene.control.Button; //導入依賴的package包/類
/**
* Initial return to home base command
* @param flightZoneView
* @param btnText
* @param stage
* @return
*/
Button makeReturnHomeButton(final FlightZoneView flightZoneView, String btnText, Stage stage){
Button platoonBtn = createButton(btnText, 120);
platoonBtn.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
try {
flightZoneView.flightManager.getFlights().groundAllFlights();
} catch (FlightZoneException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
return platoonBtn;
}
示例7: instantiate
import javafx.scene.control.Button; //導入依賴的package包/類
private void instantiate() {
Button spriteButton = new Button(myResources.getString(CREATE_NEW_SPRITE));
Button screenButton = new Button(myResources.getString(CREATE_NEW_SCREEN));
Button attributeButton = new Button(myResources.getString(CREATE_NEW_ATTRIBUTE));
spriteButton.setOnAction((clicked) -> {
Tab spriteTab = new Tab(myResources.getString(CREATE_NEW_SPRITE),
new SpriteCreationScreen(myModelData));
developerTabs.getTabs().add(spriteTab);
});
// screenButton.setOnAction((clicked) -> {
// Tab screenTab = new Tab(myResources.getString(CREATE_NEW_SCREEN),
// new ScreenModelCreator(myModelData.getScreenSprites(), myGeneralDataCreator, new ScreenModelData()));
// developerTabs.getTabs().add(screenTab);
// });
screenButton.setOnAction((clicked) -> {
// Tab screenTab = new Tab(myResources.getString(CREATE_NEW_SCREEN),
// new ScreenModelCreator(myModelData.getScreenSprites(), myGeneralDataCreator, new ScreenModelData()));
//developerTabs.getTabs().add(screenTab);
});
// attributeButton.setOnAction((clicked) -> {
// Tab attributeTab = new Tab(myResources.getString(CREATE_NEW_ATTRIBUTE), new GroundUpAttributeCreator());
// developerTabs.getTabs().add(attributeTab);
// });
this.getChildren().addAll(//spriteButton,
screenButton);//, attributeButton);
}
示例8: processDot
import javafx.scene.control.Button; //導入依賴的package包/類
@FXML
private void processDot(ActionEvent event) {
//Impede que pontos (vírgula) sejam concatenados como resultado de uma operação
if (start) {
output.setText("");
start = false;
}
//Impede que o ponto (vírgula) seja clicada mais de uma vez
if (dot) {
return;
}
//Impede que inicie um número clicando no ponto (vírgula)
if (!number1Value) {
return;
}
String value = ((Button) event.getSource()).getText();
output.setText(output.getText() + value);
dot = true;
}
示例9: NotifyTab
import javafx.scene.control.Button; //導入依賴的package包/類
public NotifyTab()
{
super();
super.setText("Notification");
super.setClosable(false);
pane = new Pane();
box = new VBox();
header = new Label();
desc = new Label();
okButton = new Button("Ok");
okButton.setPrefWidth(50);
okButton.setOnMouseClicked(new OkButtonHandler());
box.getChildren().addAll(header, desc, okButton);
box.setPadding(new Insets(15, 15, 15, 15));
box.setSpacing(15);
pane.setPrefHeight(AppTabPane.CONTENT_HEIGHT);
pane.setPrefWidth(AppTabPane.CONTENT_WIDTH);
pane.getChildren().add(box);
super.setContent(pane);
}
示例10: createMenuBar
import javafx.scene.control.Button; //導入依賴的package包/類
/**
* create the Menu Bar
*
* @param scene
*/
public MenuBar createMenuBar(Scene scene, com.bitplan.gui.App app) {
MenuBar lMenuBar = new MenuBar();
for (com.bitplan.gui.Menu amenu : app.getMainMenu().getSubMenus()) {
Menu menu = new Menu(i18n(amenu.getId()));
lMenuBar.getMenus().add(menu);
for (com.bitplan.gui.MenuItem amenuitem : amenu.getMenuItems()) {
MenuItem menuItem = new MenuItem(i18n(amenuitem.getId()));
menuItem.setOnAction(this);
menuItem.setId(amenuitem.getId());
menu.getItems().add(menuItem);
}
}
hideMenuButton = new Button(I18n.get(I18n.HIDE_MENU));
hideMenuButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
showMenuBar(scene, lMenuBar, !lMenuBar.isVisible());
}
});
return lMenuBar;
}
示例11: initData
import javafx.scene.control.Button; //導入依賴的package包/類
@Override
public void initData(Parent node, Map<String, String> bundle) {
et_download_path = (TextField) node.lookup("#et_download_path");
et_deploy_path = (TextField) node.lookup("#et_deploy_path");
et_secret = (TextField) node.lookup("#et_secret");
et_git_username = (TextField) node.lookup("#et_git_username");
et_git_passwd = (PasswordField) node.lookup("#et_git_passwd");
et_app_password = (PasswordField) node.lookup("#et_app_password");
et_app_password_second = (PasswordField) node.lookup("#et_app_password_second");
btn_submit = (Button) node.lookup("#btn_submit");
readFromProperty();
btn_submit.setOnAction(e->{
String message = "";
if(!et_app_password.getText().trim().equals(et_app_password_second.getText().trim())){
message = "�����������벻һ�£�";
DialogHelper.alert("����", message);
return;
}
if(!"".equals(et_app_password.getText().trim()) && et_app_password.getText().trim().length() < 5){
message = "���볤��̫��,������ȫ��";
DialogHelper.alert("����", message);
return;
}
writeToProperty();
});
}
示例12: buttonPressed
import javafx.scene.control.Button; //導入依賴的package包/類
@FXML
public void buttonPressed(MouseEvent actionEvent) throws IOException {
Button button = (Button)actionEvent.getSource();
if ((button).getText().equals("BACK"))
{
Stage current = (Stage)button.getScene().getWindow();
Parent root = FXMLLoader.load(getClass().getResource("menuSample.fxml"));
current.setMaximized(true);
current.setScene(new Scene(root, screenSize.getWidth(), screenSize.getHeight()));
//current.setFullScreen(true);
current.show();
}
}
示例13: ColorButtonSample
import javafx.scene.control.Button; //導入依賴的package包/類
public ColorButtonSample() {
HBox hBox = new HBox();
hBox.setSpacing(5);
for(int i=0; i<7; i++) {
Button b = new Button("Color");
b.setStyle("-fx-base: rgb("+(10*i)+","+(20*i)+","+(10*i)+");");
hBox.getChildren().add(b);
}
HBox hBox2 = new HBox();
hBox2.setSpacing(5);
hBox2.setTranslateY(30);
Button red = new Button("Red");
red.setStyle("-fx-base: red;");
Button orange = new Button("Orange");
orange.setStyle("-fx-base: orange;");
Button yellow = new Button("Yellow");
yellow.setStyle("-fx-base: yellow;");
Button green = new Button("Green");
green.setStyle("-fx-base: green;");
Button blue = new Button("Blue");
blue.setStyle("-fx-base: rgb(30,170,255);");
Button indigo = new Button("Indigo");
indigo.setStyle("-fx-base: blue;");
Button violet = new Button("Violet");
violet.setStyle("-fx-base: purple;");
hBox2.getChildren().add(red);
hBox2.getChildren().add(orange);
hBox2.getChildren().add(yellow);
hBox2.getChildren().add(green);
hBox2.getChildren().add(blue);
hBox2.getChildren().add(indigo);
hBox2.getChildren().add(violet);
VBox vBox = new VBox(20);
vBox.getChildren().addAll(hBox,hBox2);
getChildren().add(vBox);
}
示例14: createToggleFullScreenButtonInGameScreen
import javafx.scene.control.Button; //導入依賴的package包/類
public void createToggleFullScreenButtonInGameScreen(@NonNull GazePlay gazePlay) {
EventHandler<Event> eventHandler = new EventHandler<javafx.event.Event>() {
@Override
public void handle(javafx.event.Event e) {
gazePlay.toggleFullScreen();
}
};
Image buttonGraphics = new Image("data/common/images/fullscreen.png");
Button button = new Button("FullScreen", new ImageView(buttonGraphics));
button.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
// button.recomputeSizeAndPosition(scene);
menuHBox.getChildren().add(button);
}
示例15: createBrowserField
import javafx.scene.control.Button; //導入依賴的package包/類
private HBox createBrowserField() {
HBox browseFieldBox = new HBox(5);
dirField = new TextField();
dirField.setId("DirectoryField");
dirField.textProperty().addListener((observable, oldValue, newValue) -> updateOKButton());
HBox.setHgrow(dirField, Priority.ALWAYS);
Button browseButton = FXUIUtils.createButton("browse", "Browse directory", true, "Browse");
FileSelectionHandler browserListener;
String fileType = fileSelectionInfo.getFileType();
if (fileType != null) {
browserListener = new FileSelectionHandler(this,
new ExtensionFilter(fileType, Arrays.asList(fileSelectionInfo.getExtensionFilters())), this, null,
fileSelectionInfo.getTitle());
} else {
browserListener = new FileSelectionHandler(this, null, this, null, fileSelectionInfo.getTitle());
browserListener.setMode(FileSelectionHandler.DIRECTORY_CHOOSER);
}
browserListener.setPreviousDir(new File(System.getProperty(Constants.PROP_PROJECT_DIR, ProjectLayout.projectDir)));
browseButton.setOnAction(browserListener);
Label label = createLabel("Name: ");
label.setMinWidth(Region.USE_PREF_SIZE);
label.setId("FileSelectedLabel");
browseFieldBox.getChildren().addAll(label, dirField, browseButton);
VBox.setMargin(browseFieldBox, new Insets(5, 5, 5, 5));
return browseFieldBox;
}