Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » javafx problem with mutiple scenes hellp me fix it(javafx problem with mutiple scenes dont show the main scene)
icon2.gif  javafx problem with mutiple scenes hellp me fix it [message #1729775] Mon, 18 April 2016 20:17 Go to next message
Deividas VYÅ NIAUSKAS is currently offline Deividas VYÅ NIAUSKASFriend
Messages: 1
Registered: April 2016
Junior Member
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

[Updated on: Fri, 22 April 2016 10:15]

Report message to a moderator

Re: javafx problem with mutiple scenes hellp me fix it [message #1729876 is a reply to message #1729775] Tue, 19 April 2016 21:08 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6329
Registered: July 2009
Senior Member
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
Previous Topic:Color variable definitions are marked as Unknown property
Next Topic:Maven Central publishing for 2.3.0 release?
Goto Forum:
  


Current Time: Mon Jul 24 19:06:08 GMT 2017

Powered by FUDForum. Page generated in 0.03198 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software