List of usage examples for javafx.fxml FXMLLoader FXMLLoader
public FXMLLoader()
From source file:main.Content.java
public boolean showInputDialog(Activity aktivitet) { try {/*from w ww . j a v a2 s .c o m*/ FXMLLoader loader = new FXMLLoader(); loader.setLocation(Main.class.getResource("view/InputDialog.fxml")); AnchorPane page = (AnchorPane) loader.load(); Stage dialogStage = new Stage(); dialogStage.setTitle("Data Input"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.initOwner(mainApp.getPrimaryStage()); Scene scene = new Scene(page); dialogStage.setScene(scene); InputDialogController controller = loader.getController(); controller.setListData(data); controller.setDialogStage(dialogStage); controller.setData(aktivitet); dialogStage.showAndWait(); return controller.isSaveClicked(); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); return false; } }
From source file:cz.lbenda.gui.controls.TextAreaFrmController.java
/** Create new instance return main node and controller of this node and sub-nodes */ public static Tuple2<Parent, TextAreaFrmController> createNewInstance() { URL resource = TextAreaFrmController.class.getResource(FXML_RESOURCE); try {/*from w w w . j a va 2 s.c om*/ FXMLLoader loader = new FXMLLoader(); loader.setLocation(resource); loader.setBuilderFactory(new JavaFXBuilderFactory()); Parent node = loader.load(resource.openStream()); TextAreaFrmController controller = loader.getController(); return new Tuple2<>(node, controller); } catch (IOException e) { LOG.error("Problem with reading FXML", e); throw new RuntimeException("Problem with reading FXML", e); } }
From source file:main.Content.java
public void showChartOverview() { try {/*from w w w .j av a 2s .com*/ FXMLLoader loader = new FXMLLoader(); loader.setLocation(Main.class.getResource("view/tabmenu/ChartTab.fxml")); GridPane chartOverview = (GridPane) loader.load(); tabRootLayout.getTabs().get(0).setContent(chartOverview); } catch (IOException e) { e.printStackTrace(); } }
From source file:ua.com.ecotep.debtprevention.VnaklController.java
@FXML private void handleDocSelectorAction(ActionEvent event) { if (selCl == null) { AlertDialog.showSimpleMessage("? .", AlertDialog.ICON_INFO, parentInterface.getCurrentWindow()); return;//from w w w .j a v a 2 s . c om } Task<Object> task = DPSession.getInstance().getTask(); if ((task != null) && (task.isRunning())) { AlertDialog.showSimpleMessage( "? ?, -? .", AlertDialog.ICON_FORBIDDEN, parentInterface.getCurrentWindow()); return; } Scene sceneParent = parentInterface.getCurrentWindow().getScene(); final Point2D windowCoord = new Point2D(sceneParent.getWindow().getX(), sceneParent.getWindow().getY()); final Point2D sceneCoord = new Point2D(sceneParent.getX(), sceneParent.getY()); final Point2D nodeCoord = addDocButton.localToScene(0.0, 0.0); final double coordX = Math.round(windowCoord.getX() + sceneCoord.getX() + nodeCoord.getX()); final double coordY = Math .round(windowCoord.getY() + sceneCoord.getY() + nodeCoord.getY() + addDocButton.getHeight() + 6); try { selectorPopup = new Popup(); selectorPopup.setAutoHide(true); selectorPopup.setAutoFix(true); selectorPopup.setHideOnEscape(true); FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource("/fxml/DocSelectScene.fxml")); AnchorPane root = (AnchorPane) loader.load(); DocSelectController controller = loader.getController(); controller.setParentInterface(this); Scene scene = new Scene(root); scene.setFill(null); selectorPopup.getContent().add(root); selectorPopup.setX(coordX); selectorPopup.setY(coordY); selectorPopup.show(parentInterface.getCurrentWindow()); } catch (IOException ex) { Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex); AlertDialog.showSimpleMessage( "? ? !", AlertDialog.ICON_ERROR, parentInterface.getCurrentWindow()); } }
From source file:cz.lbenda.dataman.db.frm.DbConfigFrmController.java
/** Create new instance return main node and controller of this node and sub-nodes */ public static Tuple2<Parent, DbConfigFrmController> createNewInstance() { URL resource = DbConfigFrmController.class.getResource(FXML_RESOURCE); try {/* w w w . j ava 2 s .c o m*/ FXMLLoader loader = new FXMLLoader(); loader.setLocation(resource); loader.setBuilderFactory(new JavaFXBuilderFactory()); Parent node = loader.load(resource.openStream()); DbConfigFrmController controller = loader.getController(); return new Tuple2<>(node, controller); } catch (IOException e) { LOG.error("Problem with reading FXML", e); throw new RuntimeException("Problem with reading FXML", e); } }
From source file:com.properned.application.SystemController.java
@FXML public void openAboutDialog() { logger.info("Open the about dialog"); FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource("/com/properned/gui/aboutFrame.fxml")); loader.setResources(MessageReader.getInstance().getBundle()); try {/*w w w.j a v a 2 s . c o m*/ loader.load(); Parent root = loader.getRoot(); Stage modalDialog = new Stage(StageStyle.UTILITY); modalDialog.initOwner(Properned.getInstance().getPrimaryStage()); modalDialog.setTitle(MessageReader.getInstance().getMessage("menu.help.about")); modalDialog.setResizable(false); Scene scene = new Scene(root); scene.getStylesheets().add("/com/properned/style/application.css"); modalDialog.setScene(scene); modalDialog.showAndWait(); } catch (IOException e) { Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.openFrame"), e); } }
From source file:com.properned.application.SystemController.java
@FXML public void openHelpDialog() { logger.info("Open the help dialog"); FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource("/com/properned/gui/helpFrame.fxml")); loader.setResources(MessageReader.getInstance().getBundle()); try {/*from w w w.ja v a 2s .c o m*/ loader.load(); Parent root = loader.getRoot(); Stage modalDialog = new Stage(); modalDialog.setTitle(MessageReader.getInstance().getMessage("menu.help.help")); modalDialog.setResizable(true); modalDialog.getIcons().add(new Image("/com/properned/style/icon/icon_16.png")); Scene scene = new Scene(root); scene.getStylesheets().add("/com/properned/style/application.css"); modalDialog.setScene(scene); modalDialog.show(); } catch (IOException e) { Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.openFrame"), e); } }
From source file:com.properned.application.SystemController.java
@FXML public void openLocaleDialog() { logger.info("Open the locale dialog"); FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource("/com/properned/gui/localeFrame.fxml")); loader.setResources(MessageReader.getInstance().getBundle()); try {//from w w w .j a va 2 s .c om loader.load(); Parent root = loader.getRoot(); Stage modalDialog = new Stage(StageStyle.UNIFIED); modalDialog.initModality(Modality.APPLICATION_MODAL); modalDialog.initOwner(Properned.getInstance().getPrimaryStage()); modalDialog.setTitle(MessageReader.getInstance().getMessage("manageLocale.title")); modalDialog.setResizable(true); modalDialog.getIcons().add(new Image("/com/properned/style/icon/icon_16.png")); Scene scene = new Scene(root); scene.getStylesheets().add("/com/properned/style/application.css"); modalDialog.setScene(scene); modalDialog.showAndWait(); } catch (IOException e) { Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.openFrame"), e); } }
From source file:mesclasses.view.TimetableController.java
private Cours openEditDialog(Cours coursToEdit, Cours originalCours) { try {//from ww w . java 2 s .c om // Load the fxml file and create a new stage for the popup dialog. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource(Constants.COURS_EDIT_DIALOG)); AnchorPane page = (AnchorPane) loader.load(); // Create the dialog Stage. Stage dialogStage = new Stage(); dialogStage.setTitle("Edition d'un cours"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.initOwner(primaryStage); Scene scene = new Scene(page); dialogStage.setScene(scene); // Set the person into the controller. CoursEditDialogController controller = loader.getController(); controller.setDialogStage(dialogStage); controller.setCours(coursToEdit, false); // Show the dialog and wait until the user closes it dialogStage.showAndWait(); int status = controller.getStatus(); if (status >= 0) { //update/cancel return controller.getCours(); } else { //delete getPane(coursToEdit).getChildren().remove(coursToEdit.getEvent()); int seances = model.delete(originalCours).size(); ModalUtil.info("Sances modifies", seances + " sances ont t modifies"); return null; } } catch (IOException e) { notif(e); return null; } }
From source file:open.dolphin.client.MainWindowController.java
/** * Initializes the controller class.// w w w. j a v a 2s. c om * * @param url * @param rb */ @Override public void initialize(URL url, ResourceBundle rb) { //- Init TableView ReceptView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); PatientSearchView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); PatientFutureView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); LabRecieverView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); // mainTab.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { // @Override // public void changed(ObservableValue<? extends Number> ov, Number oldValue, Number newValue) { // SingleSelectionModel<Tab> selectionModel = mainTab.getSelectionModel(); // if(mainTab.getTabs() != null){ // if(selectionModel.isSelected(0)){ // karteTabPane.getTabs().clear(); // } // } // } // }); // ????? TableColumn colId = new TableColumn("ID"); recept.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("recept")); visitTime.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("visitTime")); tableCellAlignRight(visitTime); clientId.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("clientId")); name.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("name")); sex.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("sex")); tableCellAlignCenter(sex); insurance.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("insurance")); birthDay.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("birthDay")); physicianInCharge.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("physicianInCharge")); clinicalDepartments .setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("clinicalDepartments")); reservation.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("reservation")); memo.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("memo")); status.setCellValueFactory(new PropertyValueFactory<ReceptInfo, String>("status")); tableCellImageAlignCenter(status); // ???? ReceptView.getItems().setAll(fetchDataFromServer()); // ???(?) ReceptView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) { if (mouseEvent.getClickCount() == 2) { System.out.println("Double clicked"); ReceptInfo selectedUser = ((TableView<ReceptInfo>) mouseEvent.getSource()) .getSelectionModel().getSelectedItem(); // ?????????? for (ReceptInfo info : receptList) { if (info.getName().equals(selectedUser.getName())) { return; } } System.out.println(selectedUser.getClientId()); receptList.add(selectedUser); // ?? final ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem("?"); item1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Reserve Karte?"); // ?? // e.getSource(); } }); MenuItem item2 = new MenuItem("???"); item2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab and Preservation???"); karteTabPane.getTabs().remove(karteTabPane.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); MenuItem item3 = new MenuItem("?"); item3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab?"); karteTabPane.getTabs().remove(karteTabPane.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); contextMenu.getItems().addAll(item1, item2, item3); Tab tab = new Tab(selectedUser.getName()); tab.setOnClosed(new EventHandler<Event>() { @Override public void handle(Event t) { Tab tab = (Tab) t.getSource(); for (int i = 0; i < receptList.size(); i++) { if (tab.getText().equals(receptList.get(i).getName())) { receptList.remove(i); } } System.out.println("Closed!"); } }); tab.setContextMenu(contextMenu); // Right-click mouse button menu try { // Loading content on demand Parent root = (Parent) new FXMLLoader() .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream()); tab.setContent(root); karteTabPane.getSelectionModel().select(tab); karteTabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); karteTabPane.getTabs().add(tab); karteTabPane.setPrefSize(kartePane.getPrefWidth(), kartePane.getPrefHeight()); kartePane.getChildren().retainAll(); kartePane.getChildren().add(karteTabPane); } catch (IOException ex) { Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex); } } } } }); // ???? clientId1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("clientId1")); name1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("name1")); kana1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("kana1")); sex1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("sex1")); birthDay1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("birthDay1")); receiveDay1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("receiveDay1")); status1.setCellValueFactory(new PropertyValueFactory<PatientSearchInfo, String>("status1")); // dummy? PatientSearchView.getItems().setAll(fetchDataFromPatientInfo()); // ??(?) PatientSearchView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) { if (mouseEvent.getClickCount() == 2) { System.out.println("Double clicked"); PatientSearchInfo selectedUser = ((TableView<PatientSearchInfo>) mouseEvent.getSource()) .getSelectionModel().getSelectedItem(); // ?????????? for (PatientSearchInfo info : patientSearchList) { if (info.getName1().equals(selectedUser.getName1())) { return; } } System.out.println(selectedUser.getKana1()); patientSearchList.add(selectedUser); // ?? final ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem("?"); item1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Reserve Karte?"); // ?? // e.getSource(); } }); MenuItem item2 = new MenuItem("???"); item2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab and Preservation???"); karteTabPane1.getTabs().remove(karteTabPane1.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); MenuItem item3 = new MenuItem("?"); item3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab?"); karteTabPane1.getTabs().remove(karteTabPane1.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); contextMenu.getItems().addAll(item1, item2, item3); Tab tab = new Tab(selectedUser.getName1()); tab.setOnClosed(new EventHandler<Event>() { @Override public void handle(Event t) { Tab tab = (Tab) t.getSource(); for (int i = 0; i < patientSearchList.size(); i++) { if (tab.getText().equals(patientSearchList.get(i).getName1())) { patientSearchList.remove(i); } } System.out.println("Closed!"); } }); tab.setContextMenu(contextMenu); // Right-click mouse button menu try { // Loading content on demand Parent root = (Parent) new FXMLLoader() .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream()); tab.setContent(root); karteTabPane1.getSelectionModel().select(tab); karteTabPane1.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); karteTabPane1.getTabs().add(tab); karteTabPane1.setPrefSize(kartePane1.getPrefWidth(), kartePane1.getPrefHeight()); kartePane1.getChildren().retainAll(); kartePane1.getChildren().add(karteTabPane1); } catch (IOException ex) { Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex); } } } } }); // ???? clientId2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("clientId2")); name2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("name2")); kana2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("kana2")); insurance2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("insurance2")); sex2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("sex2")); birthDay2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("birthDay2")); physicianInCharge2 .setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("physicianInCharge2")); clinicalDepartments2 .setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("clinicalDepartments2")); karte2.setCellValueFactory(new PropertyValueFactory<PatientFutureInfo, String>("karte2")); // dummy? PatientFutureView.getItems().setAll(fetchDataFromPatientFutureInfo()); // ??(?) PatientFutureView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) { if (mouseEvent.getClickCount() == 2) { System.out.println("Double clicked"); PatientFutureInfo selectedUser = ((TableView<PatientFutureInfo>) mouseEvent.getSource()) .getSelectionModel().getSelectedItem(); System.out.println(selectedUser.getName2()); // ?? final ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem("?"); item1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Reserve Karte?"); // ?? // e.getSource(); } }); MenuItem item2 = new MenuItem("???"); item2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab and Preservation???"); karteTabPane2.getTabs().remove(karteTabPane2.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); MenuItem item3 = new MenuItem("?"); item3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab?"); karteTabPane2.getTabs().remove(karteTabPane2.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); contextMenu.getItems().addAll(item1, item2, item3); Tab tab = new Tab(selectedUser.getName2()); tab.setContextMenu(contextMenu); // Right-click mouse button menu try { // Loading content on demand Parent root = (Parent) new FXMLLoader() .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream()); tab.setContent(root); karteTabPane2.getSelectionModel().select(tab); karteTabPane2.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); karteTabPane2.getTabs().add(tab); karteTabPane2.setPrefSize(kartePane2.getPrefWidth(), kartePane2.getPrefHeight()); kartePane2.getChildren().retainAll(); kartePane2.getChildren().add(karteTabPane2); } catch (IOException ex) { Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex); } } } } }); // ????? lab3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("lab3")); clientId3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("clientId3")); kana3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("kana3")); karteKana3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("karteKana3")); sex3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("sex3")); karteSex3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("karteSex3")); sampleGetDay3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("sampleGetDay3")); register3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("register3")); status3.setCellValueFactory(new PropertyValueFactory<LabReceiverInfo, String>("status3")); // dummy? LabRecieverView.getItems().setAll(fetchDataFromLabRecieverInfo()); // ???(?) LabRecieverView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) { if (mouseEvent.getClickCount() == 2) { System.out.println("Double clicked"); LabReceiverInfo selectedUser = ((TableView<LabReceiverInfo>) mouseEvent.getSource()) .getSelectionModel().getSelectedItem(); System.out.println(selectedUser.getKana3()); // ?? final ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem("?"); item1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Reserve Karte?"); // ?? // e.getSource(); } }); MenuItem item2 = new MenuItem("???"); item2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab and Preservation???"); karteTabPane3.getTabs().remove(karteTabPane3.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); MenuItem item3 = new MenuItem("?"); item3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { System.out.println("Close Tab?"); karteTabPane3.getTabs().remove(karteTabPane3.getSelectionModel().getSelectedItem()); // ?? // e.getSource(); } }); contextMenu.getItems().addAll(item1, item2, item3); Tab tab = new Tab(selectedUser.getKana3()); tab.setContextMenu(contextMenu); // Right-click mouse button menu try { // Loading content on demand Parent root = (Parent) new FXMLLoader() .load(this.getClass().getResource("/resources/fxml/Karte.fxml").openStream()); tab.setContent(root); karteTabPane3.getSelectionModel().select(tab); karteTabPane3.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); karteTabPane3.getTabs().add(tab); karteTabPane3.setPrefSize(kartePane3.getPrefWidth(), kartePane3.getPrefHeight()); kartePane3.getChildren().retainAll(); kartePane3.getChildren().add(karteTabPane3); } catch (IOException ex) { Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex); } } } } }); // ??5?????? Timer exeTimer = new Timer(); Calendar cal = Calendar.getInstance(); final int sec = cal.get(Calendar.SECOND); int delay = (60 - sec) * 1000; int interval = 5 * 1000; TimerTask task = new TimerTask() { @Override public void run() { if (!stopFlag) { System.out.println("this is called every 5 seconds on UI thread"); receptUpdate(); } else { this.cancel(); } } }; exeTimer.schedule(task, delay, interval); }