Results 1 to 5 of 5
  1. #1
    Frequency is offline Member
    Join Date
    Jul 2016
    Posts
    2
    Rep Power
    0

    Default Basic File I/O JavaFX FXML Application built with Scene Builder and Netbeans IDE

    I have utilized Netbeans IDE 8.1 and JavaFX Scene Builder from Gluon to create a basic user interface with text fields.

    User Action Pathway
    1. User types in Password.
    2. User types in the three directories in the three text fields (1. PDB..., 2. 4D..., 3. 2D...).
    3. User clicks Enter and JavaFX checks if the password is "passwd_1234" and if it is, JavaFX outputs the three directories on three separate lines in a text file (to be used by other non-Java code as inputs).

    I tried learning about Java I/O (FileReader and FileWriter) but it's implementation is quite different from that of JavaFX and FXML.

    FXML Code

    Java FX Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.control.Button?>
    <?import javafx.scene.control.PasswordField?>
    <?import javafx.scene.control.TextField?>
    <?import javafx.scene.layout.AnchorPane?>
    <?import javafx.scene.text.Font?>
    <?import javafx.scene.text.Text?>
    <AnchorPane id="AnchorPane" prefHeight="292.0" prefWidth="478.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ui.UIController">
        <children>
          <PasswordField fx:id="Passwd" layoutX="208.0" layoutY="52.0" />
          <TextField fx:id="PDB" layoutX="208.0" layoutY="94.0" />
          <TextField fx:id="D4" layoutX="208.0" layoutY="129.0" />
          <TextField fx:id="D2" layoutX="208.0" layoutY="169.0" />
          <Button fx:id="Enter" layoutX="208.0" layoutY="215.0" mnemonicParsing="false" onAction="#handleButtonAction" text="Enter" />
          <Text layoutX="48.0" layoutY="112.0" strokeType="OUTSIDE" strokeWidth="0.0" text="PDB File Directory" wrappingWidth="180.3525390625">
             <font>
                <Font name="Lucida Sans Regular" size="13.0" />
             </font>
          </Text>
          <Text layoutX="48.0" layoutY="147.0" strokeType="OUTSIDE" strokeWidth="0.0" text="4D NOESY Peak List" wrappingWidth="155.00000256299973">
             <font>
                <Font name="Lucida Sans Regular" size="13.0" />
             </font>
          </Text>
          <Text layoutX="48.0" layoutY="187.0" strokeType="OUTSIDE" strokeWidth="0.0" text="2D HSQC Peak List" wrappingWidth="142.3525390625">
             <font>
                <Font name="Lucida Sans Regular" size="13.0" />
             </font>
          </Text>
          <Text layoutX="48.0" layoutY="70.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Password" wrappingWidth="180.3525390625">
             <font>
                <Font name="Lucida Sans Regular" size="13.0" />
             </font>
          </Text>
        </children>
    </AnchorPane>
    Java Code

    Java FX Code:
    package ui;
    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    public class UI extends Application {
        @Override
        public void start(Stage stage) throws Exception {
            Parent root = FXMLLoader.load(getClass().getResource("UI.fxml"));
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.show();
        }
        public static void main(String[] args) {
            launch(args);
        } 
    }
    Java Controller Code
    Java FX Code:
    package ui;
    import java.net.URL;
    import java.util.ResourceBundle;
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.fxml.Initializable;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.MenuBar;
    import javafx.scene.control.PasswordField;
    import javafx.scene.control.TextField;
    import javafx.scene.text.Text;
    public class UIController implements Initializable {  
        private Label label;
        @FXML
        private PasswordField Passwd;
        @FXML
        private TextField PDB;
        @FXML
        private TextField D4;
        @FXML
        private TextField D2;
        @FXML
        private Button Enter;
        @FXML
        private void handleButtonAction(ActionEvent event) {
            System.out.println("You clicked me!");
            label.setText("Hello World!");
        }
        @Override
        public void initialize(URL url, ResourceBundle rb) {
        }
    }
    Please assist me in the Java code (I can auto-generate the controller using Source > Make Controller in Netbeans) to implement the User Action Pathway. Thanks.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Basic File I/O JavaFX FXML Application built with Scene Builder and Netbeans IDE

    How much Java code have you done?
    I ask, because you probably ought to know about how IO works before even thinking about learning a GUI framework.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Frequency is offline Member
    Join Date
    Jul 2016
    Posts
    2
    Rep Power
    0

    Default Re: Basic File I/O JavaFX FXML Application built with Scene Builder and Netbeans IDE

    @Tolls Not too much Java code (about 1-2 weeks); I had learnt GNU Awk for about 4 months before starting on Java. I only need to develop this basic interface. One more piece of information I need is after the text file is generated, how do I get a tcsh script to run automatically and produce the necessary output? Thanks.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Basic File I/O JavaFX FXML Application built with Scene Builder and Netbeans IDE

    Java really isn't a language for that sort of "I've never worked in the language but I should be able to cobble this together" scripting.
    It bears no relationship to Awk, that's for sure.

    Just because some stuff can be generated (eg JavaFX) doesn't mean the rest works like that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Basic File I/O JavaFX FXML Application built with Scene Builder and Netbeans IDE

    I might misunderstand the complexity of the task, but to my mind you can easily do all this in the action handler of the button. What do you need the IO framework for, do you want to access a separate password repository?

    Quick and dirty solution:
    0. make sure your fxml file knows what the controller class is
    1. hook up the button to its actionHandler in the fxml file, (alternatively SceneBuilder will do it for you if you show em the method in the controller class).
    2. create the logic inside the actionHandler.
    3. printout the result of your logic on a node in your scene by setting its text property.


    If you want to access a separate password repository you can squeeze all that logic into the action handler as well.
    Last edited by benji2505; 07-12-2016 at 09:03 PM.

Similar Threads

  1. Java FXML, JavaFX, Swing?
    By ctullar in forum JavaFX
    Replies: 5
    Last Post: 07-27-2015, 04:57 PM
  2. Replies: 0
    Last Post: 12-07-2014, 06:27 PM
  3. Replies: 2
    Last Post: 10-14-2014, 04:20 PM
  4. JavaFX scene builder
    By JavaPete in forum JavaFX
    Replies: 2
    Last Post: 07-17-2014, 12:23 AM
  5. Netbeans built .jar for Mac
    By zobelogne in forum NetBeans
    Replies: 2
    Last Post: 11-03-2008, 04:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •