How to call a class within another class?
In the code below i want to call up another class to display instead of the message "Correct password". This other class Mainpage that i am trying to call is a form page. how can i proceed such that if the correct password is entered and the ok button is pressed it will call the class Mainpage which displays as a form page? Any suggestion?
publicvoid actionPerformed (ActionEvent ae)
{
String str = ae.getActionCommand();
if ("OK".equals(str))
{
char chPassword[] = txtPassword.getPassword();
String strPassword =new String (chPassword);
if (strPassword.trim() .equals("pass"))
{
JOptionPane.showMessageDialog (this,"[b]Correct Password[/b]");
}
else
{
JOptionPane.showMessageDialog (this,"Incorrect Password","Error Message" ,
JOptionPane.ERROR_MESSAGE);
}
txtPassword.selectAll();
txtPassword.requestFocusInWindow();
}
else
{
System.exit (0);
}
}
[1656 byte] By [
bakesa] at [2007-11-27 7:44:42]

i tried replacing the line of code below with new Mainpage("");
if (strPassword.trim() .equals("pass"))
{
[b]JOptionPane.showMessageDialog (this, "Correct Password][/b]");// I replaced this line of code with new Mainpage("");
}
When i enter the correct password and click on the ok button it does not display the form page (i.e new Mainpage("")). Is there something I am not doing right?
do you think the problem is coming from calling it within PasswordDemo?
bakesa at 2007-7-12 19:25:18 >

> In the code below i want to call up another class to
> display instead of the message "Correct password".
> This other class Mainpage that i am trying to call is
> a form page. how can i proceed such that if the
> correct password is entered and the ok button is
> pressed it will call the class Mainpage which
> displays as a form page? Any suggestion?
What the h閘l is a "form page"? What exactly is your class Mainpage? Does it extend JFrame? And how have you tried calling it?
Both classes, PasswordDemo and Mainpage, extend JFrame and they are both separates files.
I am trying to call class Mainpage within class Password. If the password i entered within the dialog box that class PasswordDemo outputs is correct it should call up the Mainpage as soon as i press the ok button
are things clarified now? let me know
lest i forget, the class Mainpage is suppose to display a form that one can fill out.
The lines of code below are within the class PasswordDemo. It is within these Line of code that i tried calling the class Mainpage:
public void actionPerformed (ActionEvent ae)
{
String str = ae.getActionCommand();
if ("OK".equals(str))
{
char chPassword[] = txtPassword.getPassword();
String strPassword = new String (chPassword);
if (strPassword.trim() .equals("pass"))
{
new Mainpage("");
}
else
{
JOptionPane.showMessageDialog (this, "Incorrect Password", "Error Message" ,
JOptionPane.ERROR_MESSAGE);
}
txtPassword.selectAll();
txtPassword.requestFocusInWindow();
}
else
{
System.exit (0);
}
}
Message was edited by:
bakes
Message was edited by:
bakes
bakesa at 2007-7-12 19:25:19 >
