本文整理汇总了Java中javafx.event.EventHandler类的典型用法代码示例。如果您正苦于以下问题:Java EventHandler类的具体用法?Java EventHandler怎么用?Java EventHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventHandler类属于javafx.event包,在下文中一共展示了EventHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openHelp
import javafx.event.EventHandler; //导入依赖的package包/类
@FXML
public void openHelp(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/helpPopup.fxml"));
final Scene scene = new Scene(root);
final Stage stage = new Stage();
stage.setTitle("Help");
stage.setScene(scene);
stage.show();
stage.setResizable(false);
stage.centerOnScreen();
root.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent ke) {
if (ke.getCode() == KeyCode.ESCAPE) {
System.out.println("Key Pressed: " + ke.getCode());
stage.close();
}
}
});
}
示例2: Resource
import javafx.event.EventHandler; //导入依赖的package包/类
private Resource(Scene start, String name, int startCost, long value, long delay, double mult, final MoneyListener listener){
System.out.println(name);
this.prog = (ProgressBar) start.lookup("#" + name + "_progress");
this.made = (Label) start.lookup("#" + name + "_money");
this.buy = (Button) start.lookup("#" + name + "_buy");
this.multiply = mult;
this.name = name;
this.print = (name.charAt(0) + "").toUpperCase() + name.substring(1);
this.value = value;
this.cost = startCost;
this.delay = delay;
this.listener = listener;
setText(made, print + " Earnings: " + format.format(money));
setText(buy, "(" + miners + ") Buy Miner: " + format.format((long)cost));
this.buy.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
listener.buyMiner(Resource.this.name);
}
});
}
示例3: openSubmitAction
import javafx.event.EventHandler; //导入依赖的package包/类
@FXML
public void openSubmitAction(ActionEvent event) throws IOException {
Node node = (Node) event.getSource();
final Stage stage = (Stage) node.getScene().getWindow();
final Parent home = FXMLLoader.load(getClass().getResource("/fxml/Homepage.fxml"));
final Scene hScene = new Scene(home);
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Submit.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
root.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent ke) {
if (ke.getCode() == KeyCode.ESCAPE) {
System.out.println("Key Pressed: " + ke.getCode());
stage.setScene(hScene);
}
}
});
}
示例4: createSaveFlightButton
import javafx.event.EventHandler; //导入依赖的package包/类
private Button createSaveFlightButton(Stage stage){
Button btnSaveFlight = new Button();
btnSaveFlight.setLayoutX(10);
btnSaveFlight.setLayoutY(60);;
btnSaveFlight.setText("Save Flight");
btnSaveFlight.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Flight plan (xml)");
File file = fileChooser.showSaveDialog(stage);
if (file != null) {
System.out.println("Selected " + file);
try {
fzv.setPlanningMode(false);
new SaveXMLFlight(file.getAbsolutePath(),wayPoints);
} catch (IOException | FlightZoneException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}});
return btnSaveFlight;
}
示例5: seriesRemoved
import javafx.event.EventHandler; //导入依赖的package包/类
@Override protected void seriesRemoved(Series<Number, Number> series) {
// remove all candle nodes
for (XYChart.Data<Number, Number> d : series.getData()) {
final Node candle = d.getNode();
if (shouldAnimate()) {
// fade out old candle
FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
ft.setToValue(0);
ft.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
getPlotChildren().remove(candle);
}
});
ft.play();
} else {
getPlotChildren().remove(candle);
}
}
}
示例6: createZoomOutLineChartEventHandler
import javafx.event.EventHandler; //导入依赖的package包/类
private static EventHandler<Event> createZoomOutLineChartEventHandler(LineChart<String, Number> lineChart,
Scene scene, int originalIndexInParent) {
return new EventHandler<Event>() {
@Override
public void handle(Event e) {
lineChart.removeEventHandler(MouseEvent.MOUSE_CLICKED, this);
zoomOutAndReset(lineChart);
resetToOriginalIndexInParent(lineChart, originalIndexInParent);
lineChart.addEventHandler(MouseEvent.MOUSE_CLICKED,
createZoomInLineChartEventHandler(lineChart, scene));
}
};
}
示例7: addNewWorld
import javafx.event.EventHandler; //导入依赖的package包/类
@FXML
public void addNewWorld(){
final File f = new File(AppConfig.getWorldsLocation() + newWorldName.getText());
f.mkdirs();
Button cur = new Button(f.getName());
cur.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent event) {
selectedFile = new File(AppConfig.getWorldsLocation() + f.getName());
closeWindow();
}
});
cur.setFont(bFont);
cur.minWidthProperty().bind(worlds.widthProperty().subtract(10));
worlds.getChildren().add(cur);
}
示例8: createProgressIndicatorAnimationTimeLineOnFinished
import javafx.event.EventHandler; //导入依赖的package包/类
private EventHandler<ActionEvent> createProgressIndicatorAnimationTimeLineOnFinished(WhereIsIt gameInstance) {
return new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
log.debug("FINISHED");
selected = true;
imageRectangle.removeEventFilter(MouseEvent.ANY, customInputEventHandler);
imageRectangle.removeEventFilter(GazeEvent.ANY, customInputEventHandler);
GazeUtils.removeEventFilter(imageRectangle);
if (winner) {
onCorrectCardSelected(gameInstance);
} else {
// bad card
onWrongCardSelected(gameInstance);
}
}
};
}
示例9: init
import javafx.event.EventHandler; //导入依赖的package包/类
@Override
public void init(Stage stage, Scene scene, Pane pane) {
addButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
//add transition
String eventName = eventNameTextField.getText();
if (eventName.isEmpty()) {
return;
}
RaiseEventTransition transition = new RaiseEventTransition(eventName);
entry.getTranstionList(index).add(transition);
//refresh listview
paneController.refreshListView();
stage.close();
}
});
}
示例10: makeReturnHomeButton
import javafx.event.EventHandler; //导入依赖的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;
}
示例11: makeOnButtonDownListener
import javafx.event.EventHandler; //导入依赖的package包/类
private EventHandler<MouseEvent> makeOnButtonDownListener(){
return new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if(event.getButton() == MouseButton.PRIMARY){
HitInfo i = DnDTextInput.getHitInfo((TextInputControl) event.getSource(), event);
IndexRange r = textInput.getSelection();
if(DnDTextInput.isInRange(i.getInsertionIndex(), r)){
currentSelection = r;
}
inClick = true;
}
}
};
}
示例12: init
import javafx.event.EventHandler; //导入依赖的package包/类
private void init(Stage primaryStage) {
Group root = new Group();
primaryStage.setScene(new Scene(root));
root.getChildren().add(createChart());
// create timeline to add new data every 60th of second
animation = new Timeline();
animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000/60), new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
// 6 minutes data per frame
for(int count=0; count < 6; count++) {
nextTime();
plotTime();
}
}
}));
animation.setCycleCount(Animation.INDEFINITE);
}
示例13: WebViewPane
import javafx.event.EventHandler; //导入依赖的package包/类
public WebViewPane() {
VBox.setVgrow(this, Priority.ALWAYS);
setMaxWidth(Double.MAX_VALUE);
setMaxHeight(Double.MAX_VALUE);
WebView view = new WebView();
view.setMinSize(500, 400);
view.setPrefSize(500, 400);
final WebEngine eng = view.getEngine();
eng.load("http://www.oracle.com/us/index.html");
final TextField locationField = new TextField("http://www.oracle.com/us/index.html");
locationField.setMaxHeight(Double.MAX_VALUE);
Button goButton = new Button("Go");
goButton.setDefaultButton(true);
EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
eng.load(locationField.getText().startsWith("http://") ? locationField.getText() :
"http://" + locationField.getText());
}
};
goButton.setOnAction(goAction);
locationField.setOnAction(goAction);
eng.locationProperty().addListener(new ChangeListener<String>() {
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
locationField.setText(newValue);
}
});
GridPane grid = new GridPane();
grid.setVgap(5);
grid.setHgap(5);
GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
GridPane.setConstraints(goButton,1,0);
GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
grid.getColumnConstraints().addAll(
new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)
);
grid.getChildren().addAll(locationField, goButton, view);
getChildren().add(grid);
}
示例14: bindBtStartEvents
import javafx.event.EventHandler; //导入依赖的package包/类
private void bindBtStartEvents() {
btStart.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
startGame();
}
});
}
示例15: init
import javafx.event.EventHandler; //导入依赖的package包/类
@Override
public void init(Stage stage, Scene scene, Pane pane) {
addButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
//add transition
String questName = questNameTextField.getText();
if (questName.isEmpty()) {
return;
}
GiveQuestTransition transition = new GiveQuestTransition(questName);
entry.getTranstionList(index).add(transition);
//refresh listview
paneController.refreshListView();
stage.close();
}
});
}