Here is the main snippet
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == Cancel) {
System.exit(0);
}
String user = NameField.getText(); // Username Input by the user
String password = PassField.getText(); // Password input by the user
if (user.equals("Shivam") && password.equals(res)) // If user and
// password match
{
JOptionPane.showMessageDialog(LoginBox,
"You Have Been Successfully Logged In !",
"Welcome To The Apple Store By Shivam",
JOptionPane.PLAIN_MESSAGE);
Process jf = new Process();
jf.setSize(400, 300);
jf.setVisible(true);
} else {
JOptionPane.showMessageDialog(LoginBox, "Invalid Login", "Error",
JOptionPane.ERROR_MESSAGE);
}
if (ae.getSource() == Premium) { //This is another button,if you are a member you enter your code despite of logging in
JFrame prem = new JFrame();
setLayout(new FlowLayout());
preminfo = new JTextField();
preminfo.setBounds(25, 90, 380, 30);
prem.add(preminfo);
info = preminfo.getText();
cp = new JButton("OK");
cp.setBounds(170, 130, 70, 30);
prem.add(cp);
cp.addActionListener(this);
ImagePanel pre = new ImagePanel(
new ImageIcon(
"Mypath\\Premium.png").getImage());
prem.add(pre);
prem.setSize(427, 180);
prem.setVisible(true);
preminfo.addActionListener(this);
} //Now the main messed up part
if (info.equals(pre_pass[0]) || info.equals(pre_pass[1]) //Info is the code entered by the user and pre_pass is the array which stores all the codes
|| info.equals(pre_pass[2]) || info.equals(pre_pass[3])
|| info.equals(pre_pass[4]))// Matches if the input by user is equivalent to those defined in the array
{
PremiumProcess jf2 = new PremiumProcess(); //Creates an object of this class defined later
jf2.setSize(404, 420);
jf2.setVisible(true);
} else
JOptionPane.showMessageDialog(LoginBox, "Invalid Code", "Error",
JOptionPane.ERROR_MESSAGE);
}
It always executes both the else statements,i.e Invalid code and Invalid Login
This post has been edited by Darklordshivam: 13 November 2011 - 09:03 AM

New Topic/Question
Reply


MultiQuote




|