Here is a picture of my interface when running the project in Eclipse.
And this is the interface when ran after the project is exported to a jar
控制器:
package application;
import java.io.File;
import java.io.FileNotFoundException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class Controller {
@FXML
private Button kBtn;
@FXML
private Button bpBtn;
@FXML
private Button genButton;
FileChooser fc = new FileChooser();
public static File kasasaFile;
public static File billPayFile;
public void handleKButton(ActionEvent event) {
fc.setTitle("Select Kasasa File");
kasasaFile = fc.showOpenDialog(null);
}
public void handleBPButton(ActionEvent event) {
fc.setTitle("Select Bill Pay File");
billPayFile = fc.showOpenDialog(null);
}
public void handleGenerateButton(ActionEvent event) throws FileNotFoundException {
}
}
FXML文件:
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="336.0" prefWidth="422.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.151" fx:controller="application.Controller">
<children>
<Button layoutX="180.0" layoutY="60.0" mnemonicParsing="false" text="Browse..." onAction="#handleKButton" />
<Button layoutX="180.0" layoutY="125.0" mnemonicParsing="false" text="Browse..." onAction="#handleBPButton"/>
<Label layoutX="14.0" layoutY="64.0" text="Choose Kasasa accounts file" />
<Label layoutX="14.0" layoutY="128.0" prefHeight="17.0" prefWidth="159.0" text="Choose bill pay accounts file" />
<Button layoutX="131.0" layoutY="244.0" mnemonicParsing="false" text="Generate refund document" onAction="#handleGenerateButton"/>
</children>
</AnchorPane>
主:
package application;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Sample.fxml"));
Parent root = (Parent) loader.load();
primaryStage.setScene(new Scene(root));
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException {
launch(args);
Set<String> rewardsAccountsList = new HashSet<String>();
Set<String> billPayAccountsList = new HashSet<String>();
File rewardsFile = Controller.kasasaFile;
BufferedReader rewardsBR = new BufferedReader(new InputStreamReader(new FileInputStream(rewardsFile), "utf-8"));
File billPayFile = Controller.billPayFile;
BufferedReader billPayBR = new BufferedReader(new InputStreamReader(new FileInputStream(billPayFile), "utf-8"));
// Workaround for ByteOrderMarker that is present in files on Windows' environmentsKnown bug in Java with regards to reading files
bomSkip(rewardsBR);
scanKasasa(rewardsBR, rewardsAccountsList);
scanBillPay(billPayBR, billPayAccountsList);
Set<String> intersection = intersectionOfSets(rewardsAccountsList, billPayAccountsList);
printOutFile(intersection);
}
好像我的fxml文档没有正确加载。什么会导致这个?是否与清单或资源文件有关?