how to get return values from a button to main program.
hello,
I have a main program which has a button Authenticate. On click of authenticate open a form for auth which has USERNAME FIELS AND PASSWORD.
If entered fields are true then enable editing of jtable in main program..
Basically something like this :
//main program
Authenticate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
UpdateAuth ua=new UpdateAuth();// opens form which has username and pass for authentication
ua.setVisible(true);
//need code here for enabling table
if(s=="mactus")
{
enable table editing
}
//table.repaint();
}
});
// form open for auth..(class UpdateAuth )
private String SigninMouseClicked(java.awt.event.MouseEvent evt) {
String aname=Aname.getText();
String apass=Apassword.getText();
if(aname.equals("") && apass.equals(""))
{
JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE);
}
if(!(aname.equals("") && apass.equals("")))
{
if(aname.equals("harshil") && apass.equals("harshil123"))
{
String s="mactus"; /// if username and password is success enable table editing in main program
return s;
}
else if (!aname.equals("mactus") && !apass.equals("mactus123"))
{
Aname.setText("");
Apassword.setText("");
}
}
return null;
}
Re: how to get return values from a button to main program.
So what's the question? Also, please put the [CODE] Tags around your code as it makes it easier to read.
Re: how to get return values from a button to main program.
Is the program into one Frame?
If YES,
You must create a "flag" isEnable if authentication is correct.
example :
Code:
....
private boolean correct;
if(aname.equals("harshil") && apass.equals("harshil123"))
{
setCorrect(true); // Tell if this is correct auth..
String s="mactus"; /// if username and password is success enable table editing in main program
return s;
}
//getter and setter
....
and in method for table enable, you can check :
Code:
if (isCorrect == true) {
// do enable here...
}