Example usage for javafx.fxml FXMLLoader load

List of usage examples for javafx.fxml FXMLLoader load

Introduction

In this page you can find the example usage for javafx.fxml FXMLLoader load.

Prototype

public static <T> T load(URL location) throws IOException 

Source Link

Document

Loads an object hierarchy from a FXML document.

Usage

From source file:snpviewer.SnpViewer.java

@Override
public void start(final Stage primaryStage) {
    try {/*from   www. ja v a  2  s .com*/
        //FXMLLoader loader = new FXMLLoader(SnpViewer.class.getResource("SnpView.fxml"));
        AnchorPane page = (AnchorPane) FXMLLoader.load(SnpViewer.class.getResource("SnpView.fxml"));

        Scene scene = new Scene(page);
        primaryStage.setScene(scene);
        primaryStage.setTitle("SNP Viewer");
        scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm());
        primaryStage.show();
        primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));

        /*primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            try{
                DialogResponse response = Dialogs.showConfirmDialog(primaryStage,
                           "Any unsaved changes will be lost",
                           "Really quit?", "SNP View", DialogOptions.OK_CANCEL);
                if (DialogResponse.OK.equals(response)){
                    stop();
                }else {
                    event.consume();
                }
            }catch (Exception ex) {
                Logger.getLogger(SnpViewer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        });*/
    } catch (Exception ex) {
        Logger.getLogger(SnpViewer.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:memoryaid.SetReminderController.java

@FXML
private void handleSetReminderBtnAction(ActionEvent event) throws Exception {

    System.out.println("You clicked Add Reminder!");

    String rType = (String) reminderTypeBox.getValue();
    String rName = reminderNameText.getText();
    LocalDate rSDate = startDateId.getValue();
    LocalDate rEDate = endDateId.getValue();
    List<LocalDate> reminderDates = new ArrayList<>();

    String hours = (String) reminderHhBox.getValue();
    String minutes = (String) reminderMmBox.getValue();
    String seconds = (String) reminderSsBox.getValue();
    ObservableList<String> repeat = multiSelectComboBox.getCheckModel().getCheckedItems();

    String imgPath = imagePathText.getText();

    if (rType == null || rName == null || rSDate == null || rEDate == null || hours == null || minutes == null
            || seconds == null || repeat.size() == 0 || imgPath == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error Dialog");
        alert.setHeaderText("Oops, an Error Dialog");
        alert.setContentText("Please fill all the fields");
        alert.showAndWait();// ww  w .j  a v a  2 s .co m
        System.out.println("Please fill all the fields");
    } else if (rSDate.isAfter(rEDate) == true) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error Dialog");
        alert.setHeaderText("Oops, an Error Dialog");
        alert.setContentText("End date cannot be before the Start date");
        alert.showAndWait();
        System.out.println("End date should be greater than start date");
    } else {
        String rTime = hours + ":" + minutes + ":" + seconds;
        if (rType != null && rName != null && !rName.isEmpty() && rEDate != null && hours != null
                && minutes != null && seconds != null && repeat != null && imgPath != null) {

            String destinationPath = "/Users/madhaviunnam/NetBeansProjects/MemoryAid/src/Reminders";
            File destinationPathObject = new File(destinationPath + "/" + rName + ".png");
            File sourceFilePathObject = new File(imgPath);
            FileUtils.copyFile(sourceFilePathObject, destinationPathObject);

            System.out.println(
                    "You clicked Add Reminder!" + rType + rName + rSDate + rEDate + rTime + repeat + imgPath);
            System.out.println("****Inside if");
            Reminder reminderToSet = new Reminder();
            reminderToSet.setReminderName(rName);
            reminderToSet.setReminderType(rType);
            reminderToSet.setStartDate(rSDate);
            reminderToSet.setEndDate(rEDate);

            //endDateToCheck = rEDate.plusDays(1);

            if (repeat.contains("Every Monday")) {
                reminderToSet.setRepeatMon("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.MONDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatMon("false");
            }
            if (repeat.contains("Every Tuesday")) {
                reminderToSet.setRepeatTue("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.TUESDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatTue("false");
            }
            if (repeat.contains("Every Wednesday")) {
                reminderToSet.setRepeatWed("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.WEDNESDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatWed("false");
            }
            if (repeat.contains("Every Thursday")) {
                reminderToSet.setRepeatThu("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.THURSDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatThu("false");
            }
            if (repeat.contains("Every Friday")) {
                reminderToSet.setRepeatFri("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.FRIDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatFri("false");
            }
            if (repeat.contains("Every Saturday")) {
                reminderToSet.setRepeatSat("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.SATURDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatSat("false");
            }
            if (repeat.contains("Every Sunday")) {
                reminderToSet.setRepeatSun("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.SUNDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
            } else {
                reminderToSet.setRepeatSun("false");
            }
            if (repeat.contains("None")) {
                reminderToSet.setRepeatNone("true");
                reminderDates.add(rSDate);
            } else {
                reminderToSet.setRepeatNone("false");
            }

            System.out.println("%%%%Reminder DATes" + reminderDates);
            reminderToSet.setReminderTime(rTime);
            reminderToSet.setReminderStatus("New");

            DbConnection db = new DbConnection();
            Connection conn = db.connect();
            PreparedStatement preparedStmt = null;
            String insertSql = "INSERT into Reminders(ReminderType, ReminderName, StartDate, EndDate, ReminderTime, RepeatM, RepeatT, RepeatW, RepeatTH, RepeatF, RepeatSat, RepeatSun)"
                    + "values(?,?,?,?,?,?,?,?,?,?,?,?)";
            preparedStmt = conn.prepareStatement(insertSql);
            preparedStmt.setString(1, reminderToSet.getReminderType());
            preparedStmt.setString(2, reminderToSet.getReminderName());
            preparedStmt.setString(3, reminderToSet.getStartDate().toString());
            preparedStmt.setString(4, reminderToSet.getEndDate().toString());
            preparedStmt.setString(5, reminderToSet.getReminderTime());
            preparedStmt.setString(6, reminderToSet.getRepeatMon());
            preparedStmt.setString(7, reminderToSet.getRepeatTue());
            preparedStmt.setString(8, reminderToSet.getRepeatWed());
            preparedStmt.setString(9, reminderToSet.getRepeatThu());
            preparedStmt.setString(10, reminderToSet.getRepeatFri());
            preparedStmt.setString(11, reminderToSet.getRepeatSat());
            preparedStmt.setString(12, reminderToSet.getRepeatSun());

            preparedStmt.executeUpdate();
            System.out.println("Reminder Inserted Successfully  ");
            //Get the inserted reminders RId
            String getRIdsql = "Select max(RId) as RId from Reminders";
            ResultSet rSet = conn.createStatement().executeQuery(getRIdsql);
            int newRId = 0;
            while (rSet.next()) {
                newRId = rSet.getInt(1);

            }
            System.out.println("RID ^^^^^^^^" + newRId);
            PreparedStatement preparedStmtRDetails = null;
            for (int i = 0; i < reminderDates.size(); i++) {
                String rDetailsSql = "Insert into ReminderDetails(RId,DetailNum,ReminderDate,ReminderStatus)"
                        + " values(?,?,?,?)";
                preparedStmtRDetails = conn.prepareStatement(rDetailsSql);
                preparedStmtRDetails.setInt(1, newRId);
                preparedStmtRDetails.setInt(2, i);
                preparedStmtRDetails.setString(3, reminderDates.get(i).toString());
                preparedStmtRDetails.setString(4, "New");
                preparedStmtRDetails.executeUpdate();
                System.out.println("ReminderDetails Table Insert Successfull  ");
            }
            Parent setReminder = FXMLLoader.load(getClass().getResource("SetReminder.fxml"));
            Scene set_reminder_refresh_scene = new Scene(setReminder);
            Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
            app_stage.hide();
            app_stage.setScene(set_reminder_refresh_scene);
            app_stage.show();

        } else {
            System.out.println("Inside else");
            //show alert
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error Dialog");
            alert.setHeaderText("Oops, an Error Dialog");
            alert.setContentText("Please fill all the fields");
            alert.showAndWait();

        }
    }

}

From source file:com.github.vatbub.tictactoe.view.Main.java

/**
 * The main entry point for all JavaFX applications.
 * The start method is called after the init method has returned,
 * and after the system is ready for the application to begin running.
 * <p>//w  w  w .  jav a 2 s  .c  o  m
 * NOTE: This method is called on the JavaFX Application Thread.
 * </p>
 *
 * @param primaryStage the primary stage for this application, onto which
 *                     the application scene can be set. The primary stage will be embedded in
 *                     the browser if the application was launched as an applet.
 *                     Applications may create other stages, if needed, but they will not be
 *                     primary stages and will not be embedded in the browser.
 */
@Override
public void start(Stage primaryStage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("View.fxml"));
    Scene scene = new Scene(root);
    stage = primaryStage;
    primaryStage.setMinWidth(scene.getRoot().minWidth(0) + 70);
    primaryStage.setMinHeight(scene.getRoot().minHeight(0) + 70);

    primaryStage.setScene(scene);

    // Set Icon
    primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("icon.png")));

    primaryStage.setTitle(getWindowTitle());

    primaryStage.show();
}

From source file:ui.main.MainViewController.java

private void takeCall() {
    if (contactsManager.getAvailabilityforCalling(currentChat.getParticipant())) {
        try {//w  ww .j a va 2  s  . c  om
            //default configuration and initialization of the form
            Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("ui/call/CallView.fxml"));

            Scene scene = new Scene(root);

            Stage stage = new Stage();

            stage.setScene(scene);
            stage.show();

            stage.setResizable(false);
            stage.setTitle("IMP : Voice");
        } catch (IOException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle("IMP");
        alert.setHeaderText("Username is unavailable for calling!");
        alert.setContentText("The user is not available for calling. "
                + "Please contact the user or the server administrator");
        alert.showAndWait();
    }
}

From source file:ui.main.MainViewController.java

private void createNewConversation() {
    //this method displays the new convesation create view
    try {/*from   ww  w.  j  a v a  2  s  .c om*/
        //default configuration and initialization of the form
        Parent root = FXMLLoader
                .load(getClass().getClassLoader().getResource("ui/conversation/ConversationView.fxml"));

        Scene scene = new Scene(root);

        Stage stage = new Stage();

        stage.setScene(scene);
        stage.show();

        stage.setResizable(false);
        stage.setTitle("IMP : Conversation Creation");

        final Stage mainStage = (Stage) presence.getScene().getWindow();
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                showConversations();
            }
        });

    } catch (IOException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:patientmanagerv1.HomeController.java

@FXML
private void loadProgressReport(javafx.event.ActionEvent event) throws IOException {
    try {//from   w ww .ja va2  s. com

        //sets current report
        String currRep = listOfProgressReports.getSelectionModel().getSelectedItem().toString();
        currRep = currRep.replace(":", "");
        //System.out.println("Selected Report is: " + currRep);

        File currentReport = new File(
                installationPath + "/userdata/" + firstName + lastName + dob + "/currentprogressreport.txt");
        FileWriter f = new FileWriter(currentReport, false);
        BufferedWriter b = new BufferedWriter(f);
        f.append(currRep);
        b.close();
        f.close();

        //creates the "loaded" file & writes to the "loaded" file
        File newFile = new File(
                installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/loaded.txt");
        FileWriter fr = new FileWriter(newFile, false);
        BufferedWriter bufferedwriter2 = new BufferedWriter(fr);
        fr.append("true");
        bufferedwriter2.close();
        fr.close();

        //redirects to the progress note form
        Parent root3 = FXMLLoader.load(getClass().getResource("FXMLProgressReport.fxml"));
        Scene scene = new Scene(root3);
        Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        appStage.setScene(scene);
        appStage.show();

        /*
            DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy(HH:mm:ss)");
            Date date = new Date();
            //System.out.println(dateFormat.format(date));
            String alpha = dateFormat.format(date);
            String beta = alpha.replace(":", "");
                
                
        //writes the new report to the list
        File openProgressReportsList = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressReports.txt");
        FileWriter fw = new FileWriter(openProgressReportsList, true);           
        BufferedWriter bufferedwriter = new BufferedWriter(fw);
        fw.append(alpha + "\n");
        bufferedwriter.close();
        fw.close();
                
        //sets the new report as the current report
        File currentReport = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/currentprogressreport.txt");
        FileWriter f = new FileWriter(currentReport, false);           
        BufferedWriter b = new BufferedWriter(f);
        f.append(beta);
        b.close();
        f.close();
                
                
        //creates the folder for THIS progress report, and all blank progress report files
            File aNewProgressReport = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta);        
            System.out.println(alpha);
                
        try
        {
           aNewProgressReport.mkdir();
               // System.out.println("Hello World");
           //result = true;
        } 
               catch(Exception e)
        {
           System.out.println("directory not created: installationPath + \"/userdata/\" + firstName + lastName + dob + \"/ProgressNotes/\" + alpha");
        }  
                    
        File fN = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta + "/firstname.txt");
        FileWriter writ = new FileWriter(fN, true);           
        BufferedWriter bw = new BufferedWriter(writ);
        writ.append(firstName);
        bw.close();
        writ.close();
                
        File lN = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta + "/lastname.txt");
        FileWriter writ1 = new FileWriter(lN, true);           
        BufferedWriter bw1 = new BufferedWriter(writ1);
        writ1.append(lastName);
        bw1.close();
        writ1.close();
                
        File age = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta + "/age.txt");
        FileWriter writ2 = new FileWriter(age, true);           
        BufferedWriter bw2 = new BufferedWriter(writ2);
        writ2.append("");
        bw2.close();
        writ2.close();
        */
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Please select a progress report from the list and try again");
    }
}

From source file:patientmanagerv1.HomeController.java

@FXML
private void createNewProgressReport(javafx.event.ActionEvent event) throws IOException {
    saveEval();/* w  ww. ja v  a2s  . com*/

    DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy(HH:mm:ss)");
    Date date = new Date();
    //System.out.println(dateFormat.format(date));
    String alpha = dateFormat.format(date);
    String beta = alpha.replace(":", "");

    //writes the new report to the list
    File openProgressReportsList = new File(
            installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressReports.txt");
    FileWriter fw = new FileWriter(openProgressReportsList, true);
    BufferedWriter bufferedwriter = new BufferedWriter(fw);
    fw.append(alpha + "\n");
    bufferedwriter.close();
    fw.close();

    //sets the new report as the current report
    File currentReport = new File(
            installationPath + "/userdata/" + firstName + lastName + dob + "/currentprogressreport.txt");
    FileWriter f = new FileWriter(currentReport, false);
    BufferedWriter b = new BufferedWriter(f);
    f.append(beta);
    b.close();
    f.close();

    //creates the folder for THIS progress report, and all blank progress report files
    File aNewProgressReport = new File(
            installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta);
    //System.out.println(alpha);

    try {
        aNewProgressReport.mkdir();
        // System.out.println("Hello World");
        //result = true;
    } catch (Exception e) {
        //System.out.println("directory not created: installationPath + \"/userdata/\" + firstName + lastName + dob + \"/ProgressNotes/\" + alpha");
    }

    File fN = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta
            + "/firstname.txt");
    FileWriter writ = new FileWriter(fN, true);
    BufferedWriter bw = new BufferedWriter(writ);
    writ.append(firstName);
    bw.close();
    writ.close();

    File lN = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta
            + "/lastname.txt");
    FileWriter writ1 = new FileWriter(lN, true);
    BufferedWriter bw1 = new BufferedWriter(writ1);
    writ1.append(lastName);
    bw1.close();
    writ1.close();

    File age = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + beta
            + "/age.txt");
    FileWriter writ2 = new FileWriter(age, true);
    BufferedWriter bw2 = new BufferedWriter(writ2);
    writ2.append("");
    bw2.close();
    writ2.close();

    //creates the "loaded" file & writes to the "loaded" file
    File newFile = new File(
            installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + "/loaded.txt");
    FileWriter fr = new FileWriter(newFile, false);
    BufferedWriter bufferedwriter2 = new BufferedWriter(fr);
    fr.append("false");
    bufferedwriter2.close();
    fr.close();

    //redirects to the progress note form
    Parent root3 = FXMLLoader.load(getClass().getResource("FXMLProgressReport.fxml"));
    Scene scene = new Scene(root3);
    Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    appStage.setScene(scene);
    appStage.show();
}

From source file:patientmanagerv1.HomeController.java

@FXML
private void toPatientSelection(javafx.event.ActionEvent event) throws IOException {
    /*JOptionPane pane = new JOptionPane();
    Object[] possibleValues = {"Yes", "No", "Cancel"};
    pane.setSelectionValues(possibleValues);
    JDialog dialog = pane.createDialog("Save changes?");
    dialog.show();//from w ww  .java 2  s  .c om
    Object selectedValue = pane.getValue();*/

    int result = JOptionPane.showConfirmDialog(null, "Do you want to save any unsaved changes?",
            "Save changes?", JOptionPane.YES_NO_CANCEL_OPTION);
    //System.out.println(result);
    //JOptionPane.showConfirmDialog(null, "Would you like to save any changes before logging out?", "save changes?", YES_NO_CANCEL_OPTION);
    //Object selection = JOptionPane.get    

    if (result == 0) {
        saveEval();
        Parent root3 = FXMLLoader.load(getClass().getResource("FXMLLogin.fxml"));
        Scene scene = new Scene(root3);
        Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        appStage.setScene(scene);
        appStage.show();
    }
    if (result == 1) {
        Parent root3 = FXMLLoader.load(getClass().getResource("FXMLLogin.fxml"));
        Scene scene = new Scene(root3);
        Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        appStage.setScene(scene);
        appStage.show();
    }
    if (result == 2) {

    }
    /*Parent root3 = FXMLLoader.load(getClass().getResource("FXMLLogin.fxml"));
    Scene scene = new Scene(root3);
    Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    appStage.setScene(scene);
    appStage.show();
     */
}

From source file:patientmanagerv1.HomeController.java

@FXML
private void toPatientSelectionNoDialog(javafx.event.ActionEvent event) throws IOException {

    Parent root3 = FXMLLoader.load(getClass().getResource("FXMLLogin.fxml"));
    Scene scene = new Scene(root3);
    Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    appStage.setScene(scene);/*w w w  .  java  2 s .  c  o  m*/
    appStage.show();

}