|
Re: javafx problem with mutiple scenes hellp me fix it [message #1729876 is a reply to message #1729775] |
Tue, 19 April 2016 17:08  |
Eclipse User |
|
|
|
You'd better ask at a general JavaFX forum and/or Stackoverflow as this
question has nothing todo with e(fx)clipse in general but is pure FX.
Tom
On 19.04.16 14:17, Deividas VYÅ NIAUSKAS wrote:
> Hi all
> Soo i had been making program with login and with sql database .
> the Programs begins login scene pops out and then u press login and
> there sould be shown new scene with main program but error pops out and
> thats it dont know weres the problem rlly
>
> Main.java
>
> Quote:
>> public class Main extends Application {
>> @Override
>> public void start(Stage primaryStage) {
>> try {
>> Parent root =
>> FXMLLoader.load(getClass().getResource("view/Login.fxml"));
>> Scene scene = new Scene(root);
>>
>> 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);
>> }
>> }
>
>
> LoginControler.java
> Quote:
>> public class LoginController implements Initializable {
>> public LoginModel loginModel = new LoginModel();
>>
>> @FXML
>> private Label isConnected;
>> @FXML
>> private TextField txtUsername;
>> @FXML
>> private TextField txtPassword;
>>
>> @Override
>> public void initialize(URL location, ResourceBundle resources) {
>> // TODO Auto-generated method stub
>> if (loginModel.isDbConnected()) {
>> isConnected.setText("Connected");
>> } else {
>> isConnected.setText("Not Connected");
>> }
>> }
>> public void Login(ActionEvent event){
>> try {
>> if (loginModel.isLogin(txtUsername.getText(),
>> txtPassword.getText())){
>> isConnected.setText("username and password is correct");
>> ((Node)event.getSource()).getScene().getWindow().hide();
>> Stage primaryStage = new Stage();
>> FXMLLoader loader = new FXMLLoader();
>> Pane root =
>> loader.load(getClass().getResource("view/test1.fxml").openStream());
>> CompanyMainController companyMainController =
>> (CompanyMainController)loader.getController();
>> companyMainController.GetUser(txtUsername.getText());
>> Scene scene = new Scene(root);
>>
>> scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
>>
>> primaryStage.setScene(scene);
>> primaryStage.show();
>> } else {
>> isConnected.setText("username and password is not correct");
>> }
>> } catch (SQLException e) {
>> isConnected.setText("username and password is not correct");
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> } catch (IOException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>> }
>
>
> mainprogram controler
> Quote:
>> public class CompanyMainController implements Initializable {
>> @FXML
>> private Label userLbl;
>> @Override
>> public void initialize(URL location, ResourceBundle resources) {
>> // TODO Auto-generated method stub
>>
>> }
>>
>> public void GetUser(String user) {
>> // TODO Auto-generated method stub
>> userLbl.setText(user);
>> }
>>
>> public void SignOut(ActionEvent event) {
>> try {
>> ((Node)event.getSource()).getScene().getWindow().hide();
>> Stage primaryStage = new Stage();
>> FXMLLoader loader = new FXMLLoader();
>> Pane root =
>> loader.load(getClass().getResource("/application/Login.fxml").openStream());
>>
>>
>> Scene scene = new Scene(root);
>>
>> scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
>>
>> primaryStage.setScene(scene);
>> primaryStage.show();
>> } catch (Exception e) {
>> // TODO: handle exception
>> }
>> }
>> }
>
>
> login model
> Quote:
>> public class LoginModel {
>> Connection conection;
>> public LoginModel () {
>> conection = SqliteConnection.Connector();
>>
>> //*******************************if not conected all
>> closes************************************
>> if (conection == null) {
>>
>> System.out.println("connection not successful");
>> System.exit(1);}
>> }
>>
>> public boolean isDbConnected() {
>> try {
>> return !conection.isClosed();
>> } catch (SQLException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> return false;
>> }
>> }
>> public boolean isLogin(String user, String pass) throws
>> SQLException {
>> PreparedStatement preparedStatement = null;
>> ResultSet resultSet = null;
>> // soo this one is searcing in db employee section for
>> username and password
>> String query = "select * from employee where username = ?
>> and password = ?";
>> try {
>> preparedStatement = conection.prepareStatement(query);
>> preparedStatement.setString(1, user);
>> preparedStatement.setString(2, pass);
>>
>> resultSet = preparedStatement.executeQuery();
>> if (resultSet.next()) {
>> return true;
>> }
>> else {
>> return false;
>> }
>>
>> } catch (Exception e) {
>> return false;
>> // TODO: handle exception
>> } finally {
>> preparedStatement.close();
>> resultSet.close();
>> }
>> }
>> }
>
>
> soo anyone know why it dont show anyting for me? and how to fix it
|
|
|
Powered by
FUDForum. Page generated in 0.04128 seconds