Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.Writer;
- import java.net.URL;
- import java.util.ResourceBundle;
- import Objects.Goal;
- import UtilityClasses.GoalManager;
- import javafx.application.Application;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.fxml.Initializable;
- import javafx.stage.Stage;
- import javafx.scene.Scene;
- import javafx.scene.control.TableColumn;
- import javafx.scene.control.TableView;
- import javafx.scene.control.cell.PropertyValueFactory;
- import javafx.scene.layout.AnchorPane;
- public class Main extends Application implements Initializable {
- private Stage primaryStage;
- private AnchorPane mainLayout;
- public static ObservableList<Goal> goalsData = FXCollections.observableArrayList();
- @FXML
- static TableView<Goal> goalTable = new TableView<Goal>();
- @FXML
- static TableColumn<Goal, String> goalsColumn = new TableColumn<>();
- @FXML
- static TableColumn<Goal, String> statusColumn = new TableColumn<>();
- @Override
- public void start(Stage primaryStage) {
- this.primaryStage = primaryStage;
- this.primaryStage.setTitle("MainWindow");
- try {
- showMainView();
- } catch (IOException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void main(String[] args) {
- try {
- setDefaultSettings();
- launch(args);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- private void showMainView() throws IOException {
- SettingControlls mainController = new SettingControlls();
- FXMLLoader loader = new FXMLLoader();
- loader.setController(mainController);
- loader.setLocation(Main.class.getResource("mainFXML.fxml"));
- mainLayout = loader.load();
- Scene scene = new Scene(mainLayout);
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- private static void setDefaultSettings() throws IOException {
- File f = new File("Goals.txt");
- if(!f.exists()) {
- OutputStream os = new FileOutputStream("Goals.txt");
- Writer w = new OutputStreamWriter(os);
- w.close();
- }
- }
- private static ObservableList<Goal> getObservableList() throws FileNotFoundException, IOException {
- ObservableList<Goal> ol = FXCollections.observableArrayList(new Goal("testGoal"));
- return ol;
- }
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- goalsData.add(new Goal("test"));
- System.out.println(goalsData.get(0).getGoal());
- goalsColumn.setCellValueFactory(new PropertyValueFactory<Goal, String>("goal"));
- statusColumn.setCellValueFactory(new PropertyValueFactory<Goal, String>("status"));
- goalTable.setItems(goalsData);
- }
- }
- package Objects;
- import javafx.beans.property.SimpleStringProperty;
- public class Goal {
- private SimpleStringProperty goal;
- private SimpleStringProperty status;
- public Goal(String goal) {
- this.goal = new SimpleStringProperty(goal);
- this.status = new SimpleStringProperty("ongoing");
- }
- public Goal(String goal, String status) {
- this.goal = new SimpleStringProperty(goal);
- this.status = new SimpleStringProperty(status);
- }
- public String getGoal() {
- return this.goal.get();
- }
- public String getStatus() {
- return this.status.get();
- }
- public void setGoal(String newGoal) {
- this.goal = new SimpleStringProperty(newGoal);
- }
- public void setStatus(String newStatus) {
- this.status = new SimpleStringProperty(newStatus);
- }
- }
Add Comment
Please, Sign In to add comment