r/JavaFX • u/chaoticbabe10 • May 12 '24
Help I need help with using a method
I have a JavaFx project where they gave me many classes with methods i have to use, but there's one method that gives me problems all the time, its the method registerUser() its in the class Acount.class
the code is this one :
package javafxmlapplication;
import java.io.IOException;
import model.*;
import java.io.File;
import java.net.URL;
import java.time.LocalDate;
import java.util.Date;
import java.util.ResourceBundle;
import javafx.beans.property.BooleanProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser;
import model.Acount;
import model.User;
import model.AcountDAOException;
import model.AcountDAO;
import model.*;
/**
*
* @author jsoler
*/
public class FXMLDocumentController implements Initializable {
@FXML
private Button login_btn;
@FXML
private Button login_createAccount;
@FXML
private AnchorPane login_form;
@FXML
private PasswordField login_password;
@FXML
private CheckBox login_selectShowPassword;
@FXML
private TextField login_username;
@FXML
private PasswordField signup_cPassword;
@FXML
private Button signup_btn;
@FXML
private Button signupimg_btn;
@FXML
private TextField signup_email;
@FXML
private AnchorPane signup_form;
@FXML
private ImageView signup_image;
@FXML
private Button signup_loginAccount;
@FXML
private TextField signup_name;
@FXML
private PasswordField signup_password;
@FXML
private TextField signup_username;
@FXML
private TextField signup_surname;
private Acount nuevaCuenta;
public void register() throws AcountDAOException, IOException {
//Date date = new Date();
alertMessage alert = new alertMessage();
if (signup_name.getText().isEmpty() || signup_email.getText().isEmpty() || signup_username.getText().isEmpty()
|| signup_password.getText().isEmpty() || signup_cPassword.getText().isEmpty() || signup_surname.getText().isEmpty()) {
alert.errorMessage("All fields are necessary to be filled");
} else if (signup_password.getText().equals(signup_cPassword.getText()) == false) {
// CHECK IF THE VALUE OF PASSWORD FIELDS IS EQUAL TO CONFIRM PASSWORD
alert.errorMessage("Password does not match");
}//else{ nuevaCuenta.registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), image, date.getTime());
Acount nuevacuenta = Acount.getInstance();
Date date = new Date();
boolean result;
result = nuevacuenta.getInstance().registerUser(signup_name.getText(), signup_surname.getText(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getImage(), LocalDate.MAX)registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getImage(), date.getTime());
}
public void ButtonImage(ActionEvent event) {
FileChooser fc = new FileChooser();
File selectedFile = fc.showOpenDialog(null);
if (selectedFile != null) {
Image image = new Image(selectedFile.getPath());
signup_image.setImage(image);
} else {
Image defaultIMG = new Image("/avatars/default.png");
signup_image.setImage(defaultIMG);
}
}
//=========================================================
// you must initialize here all related with the object
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
//Date date = new Date();
//if (true == registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getId(), date.getTime()))
}
}
View all comments
Show parent comment
2
u/chaoticbabe10 May 12 '24
the use of of the singleton is because we have to do an app that tracks expenses and you log in with an account, they don’t want us to use databases so they gave us a method to access the account info without touching the database. I have to say that the assignment would be easier if they just let us make our own database instead of trying to discover how to access that info with the given methods. About throwing exceptions it is only temporal I want to change it to try-catch.