How can i close a FrameView java - java

I've tried everything and i cant get with the answer, there is not much topics talking about it.
Here the escenario:
Once the user run the app, 2 FrameViews display. The main frame and the login.
Whenever if the user exist, the login frameview must be close and let me edit the main_frame.
But i cannot close the login frameview. Dispose doesnt exist, close neither. What do i have to do?
the login form is name
demo
and the main_frame
main_frame
Suggestions?
Update
HERE the code where the login login must be close
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
String pass = this.jTextField1.getText();
String user = this.jTextField2.getText();
boolean login = db.Qboolean(new String[]{
"SELECT Id_User FROM login WHERE UserName = ? AND Pass = ?",
pass +","+user,
});
if(login)
//what do i have to use here to close it!!!
else
Logs.Mensaje("No se pudo :(");
}

If you're using Netbeans , there is another way (and easy) to check username and password !
you can define a new Jfram in run(){ }
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
//here you can make log in form within while and check if the user is exist
//continue
new Graphic().setVisible(true);
}

Related

Why this if statement doesn't execute properly?

I am using Netbeans to create a login system which then gets redirected to an Account page. However I'm stuck on this if statement and need help.
private void loginBtnActionPerformed(java.awt.event.ActionEvent evt) {
String password = passWord.getText();
String username = userName.getText();
if("red".equals(password) && ("safdari".equals(username))) {
MembershipPage Account = new MembershipPage();
Account.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "login is incorrect!");
}
}
What's expected is for another JFrame to open up after I type in the login credentials "safdari" and "red". However, for some reason that's not the case and the else statement activates instead. I'm confused new to Java btw.

GWT Getting username from url only works after refresh

My login based application, requires to always know the username of the logged in user. (MVP) . So I'm getting the username from the url, but when the page opens after the login succeeded, I can't get the username from the url, because it does not appear to exists, but it is there. It only works after a refresh. Then I'm able to get the username.
The URL is in the form http://127.0.0.1:8888/AdministrareBloc.html#AdminPlace:admin, where I'm splitting the String to only get the admin part.
I thought this is because it downloads the code before verifying the user. So I placed a split point in my code like this: (I don't know if I placed it correctly)
loginButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
final String username = usernameBox.getText();
final String password = passwordBox.getText();
GWT.runAsync(new RunAsyncCallback() {
#Override
public void onSuccess() {
performUserConnection(username, password);
}
#Override
public void onFailure(Throwable reason) {
// TODO Auto-generated method stub
}
});
}
});
private static void performUserConnection(String username, String password) {
DBConnectionAsync rpcService = (DBConnectionAsync) GWT.create(DBConnection.class);
ServiceDefTarget target = (ServiceDefTarget) rpcService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
target.setServiceEntryPoint(moduleRelativeURL);
rpcService.authenticateUser(username, password, new AsyncCallback<User>() {
#Override
public void onSuccess(User user) {
if (user.getType().equals("User")) {
String username = user.getUsername();
presenter.goTo(new UserPlace(username));
} else if (user.getType().equals("Admin")) {
String username = user.getUsername();
presenter.goTo(new AdminPlace(username));
}
}
}
}
This is happening when the user clicks the login button. Is the split point placed correclty, or not ? How can I get the username without needing to refresh the page after a successful login ?
UPDATE
I've tried a trick today, placing a Window.Location.reload() inside the AdminViewImpl and UserViewImpl, and when the application starts, then the page reloads every second, so this means for me that the split point is not correclty used and the browser downloads the code before he actually needs it, and that's why I'm able to see the username after the refresh, because it redownloads the code, and I'm already logged in when I refresh.
Thanks in advance

how to close login form while being redirected to the main form java

I'm making a login form in java and i having trouble with the it. Whats happening is that regardless of whether the username are correct or not the form closes. I know that the dispose; isn't suppose to be placed in its position but everytime that i attempt to place it elsewhere I'm having error in my code. This is the code that I have
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String user=jTextField1.getText();
String pwd= new String (jPasswordField1.getPassword());
if (user.equals("admin") && pwd.equals("1234"))
new Main().setVisible(true);
else {
JOptionPane.showMessageDialog(this, "Incorrect Username or Password!");
}
dispose;
}
I'm fairly new to java, so please help me

Register user to QuickBlox Users from android

I'm trying to use QuickBlox in my android application, I read the guide and imported the sample and everything worked fine.
I changed a few things that user can login using EditText for username and another for password.. and it worked fine.
But now I want to add a Register Button that makes the user able to register new account.. I don't know how to do that.. Any Idea?
Here's the solution :
QBUsers.signUp(user, new QBEntityCallbackImpl<QBUser>() {
public void onSuccess(QBUser result, Bundle params) {
// success
}
public void onError(List<String> errors) {
AlertDialog.Builder dialog = new AlertDialog.Builder(
SplashActivity.this);
dialog.setMessage(
"register errors: " + errors)
.create().show();
}
});

Changing the text of a JLabel and status of JMenuItem during runtime

I am developing an application in which I would like to display the username on the top of the screen after the user has logged into the system. Also I need to enable five JMenuItems only after the user has been logged in. I used the following code and called it from the successful logon If condition but it does no change to the application at all.
NOTE :- The username is to be displayed in the JFrame and the login form is a JInternalFrame
All JMenuItems are also in the JFrame
obj2 is the object created for the LoginModel class in order to retrieve the username
private String global_username="";
public String getGlobalUsername(){
return global_username;
}
The method which I call to change the state of the JMenuItems and to set the value of the JLabel
public void disableMenues(){
mntmSupplierManagement.setEnabled(false);
mntmEmployeeManagement.setEnabled(false);
mntmStockManagement.setEnabled(false);
mntmReporting.setEnabled(false);
mntmTransaction.setEnabled(false);
userName.setText("Logged in as "+obj2.getGlobalUsername());
}
I used the code below in the JInternalFrame (Login form) in order to call the above method after the user has been logged on
if(username.equals(user)&&password.equals(pass)){
System.out.println("Logged into the system");
global_username=username;
accountType=acc;
updateView();
else{
System.out.println("Unsuccessful login");
updateView();
}
Also I used the following code to create the JLabel
JLabel userName=new JLabel();
userName.setText("Logged in as "+obj2.getGlobalUsername());
This gave me a NullPointerException so I changed it to
userName.setText("Logged in as ");
Any Help is Greatly Appreciated
Thanks in Advance Everyone!!!
I would recommend having a single variable to track whether the user is logged in or not and then bind your components appropriately
private boolean loggedIn = false;
public void disableMenues(){
mntmSupplierManagement.setEnabled(!loggedIn);
mntmEmployeeManagement.setEnabled(!loggedIn);
mntmStockManagement.setEnabled(!loggedIn);
mntmReporting.setEnabled(!loggedIn);
mntmTransaction.setEnabled(!loggedIn);
userName.setText("Logged in as "+obj2.getGlobalUsername());
}
I would also suggest to track the LoginModel class throughout the session
private LoginModel lm = null;
private void authenticate(String username, String password){
//check username password (database maybe)
//and return the LoginModel for the pair
lm = returnedLoginModel;
}
And then in the JFrame all you have to do is
if(lm != null){
System.out.println("Logged into the system");
loggedIn = true;
updateView();
else{
System.out.println("Unsuccessful login");
loggedIn = false;
updateView();
}
Keep in mind that you have to track the logout as well
private void logout(){
lm = null;
}

Categories