I have utilized Netbeans IDE 8.1 and JavaFX Scene Builder from Gluon to create a basic user interface with text fields.
I tried learning about Java I/O (FileReader and FileWriter) but it's implementation is quite different from that of JavaFX and FXML.
<?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>
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);
}
}
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.
答案 0 :(得分:0)
您可以使用PrintWriter。要检查密码是否相同,只需使用getText()并使用equals
。
您创建文件并写入:
PrintWriter writer = new PrintWriter(new FileWriter(file));
然后你阅读每个领域并做
writer.println(directoryName);
不要忘记使用writer.flush();
,因为默认情况下它不是自动的。
- &gt; Oracle tutorial更好地解释了它。