Disable Javafx TextField and Buttons after a fixed set of days

By | July 12, 2018
Questions:

So i have created a Data Entry Application using Javafx and Ms Access, but i wanted to add a feature which i don’t know how to implement. I want my application to run for 6 days only and after that all my buttons and textfields will be disabled.

when i click the start button it will setdisable(false) all my buttons and textfields and will start the day count and setdisable(true) Start button forever. I want to store this info in some hidden .txt file so that when the application closes it will remember the start button status and day count and also display the day no. in a label. At the end of 6th day all my buttons and textfields will be disabled forever.

This is my main class:

package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;


public class DataEntryMain extends Application {
@Override
public void start(Stage primaryStage) {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("/application/UI.fxml"));
        Scene scene = new Scene(root,1280,700);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.show();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    launch(args);
}

}

This is my Controller class:

package application;

import java.sql.SQLException;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextField;

import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;

public class DataEntryController {

int rn;

@FXML
private JFXTextField t1, t2, t3, t4 , t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;

@FXML
private JFXButton start;

@FXML
private JFXButton lock;

@FXML
private JFXButton save;

@FXML
private JFXButton update;

@FXML
private Label resultConsole;

@FXML
private JFXTextField searchRowNo;

@FXML
private TableView<DataEntry> tabView;

@FXML
private TableColumn<DataEntry, Integer> rowNumber;

@FXML
private TableColumn<DataEntry, String> c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15;

@FXML
private void insertData(ActionEvent event) throws ClassNotFoundException, SQLException{
    try {
    DataEntryModel.insertData(t1.getText(), t2.getText(), t3.getText(), t4.getText(), t5.getText(), t6.getText(), t7.getText(), t8.getText(), t9.getText(), t10.getText(), t11.getText(), t12.getText(), t13.getText(), t14.getText(), t15.getText());
    resultConsole.setText("Data Added Successfully!");

    }
    catch(SQLException e) {
        System.out.println("Exception Occer In Insertion "+e);
        e.printStackTrace();
        throw e;
    }
}

@FXML
private void updateData(ActionEvent event) throws ClassNotFoundException, SQLException{
    rn = Integer.parseInt(searchRowNo.getText());
    try {
        DataEntryModel.updateData(rn, t1.getText(), t2.getText(), t3.getText(), t4.getText(), t5.getText(), t6.getText(), t7.getText(), t8.getText(), t9.getText(), t10.getText(), t11.getText(), t12.getText(), t13.getText(), t14.getText(), t15.getText());

        resultConsole.setText("Data Updated Successfully!");
    }
        catch(SQLException e) {
            System.out.println("Exception  Occure In Update "+e);
            throw e;
        }

}

@FXML
private void intialize()throws Exception{

    rowNumber.setCellValueFactory(cellData -> cellData.getValue().getRNo().asObject());

    c1.setCellValueFactory(cellData -> cellData.getValue().getText1());
    c2.setCellValueFactory(cellData -> cellData.getValue().getText2());
    c3.setCellValueFactory(cellData -> cellData.getValue().getText3());
    c4.setCellValueFactory(cellData -> cellData.getValue().getText4());
    c5.setCellValueFactory(cellData -> cellData.getValue().getText5());
    c6.setCellValueFactory(cellData -> cellData.getValue().getText6());
    c7.setCellValueFactory(cellData -> cellData.getValue().getText7());
    c8.setCellValueFactory(cellData -> cellData.getValue().getText8());
    c9.setCellValueFactory(cellData -> cellData.getValue().getText9());
    c10.setCellValueFactory(cellData -> cellData.getValue().getText10());
    c11.setCellValueFactory(cellData -> cellData.getValue().getText11());
    c12.setCellValueFactory(cellData -> cellData.getValue().getText12());
    c13.setCellValueFactory(cellData -> cellData.getValue().getText13());
    c14.setCellValueFactory(cellData -> cellData.getValue().getText14());
    c15.setCellValueFactory(cellData -> cellData.getValue().getText15());

    ObservableList<DataEntry> deList = DataEntryModel.getAllRecords();
    populateTable(deList);
}

private void populateTable(ObservableList<DataEntry> deList) {
    tabView.setItems(deList);

}

}

I have 3 other classes which i have used for database operations and i don’t think that’s relevant here.This is how the application looks

Answers:

Leave a Reply

Your email address will not be published. Required fields are marked *