please ignore this thread. sorryl
Printable View
please ignore this thread. sorryl
I believe you need to put it inside you class. You can't have the main method outside of the class :)
So put it in before the ending } of your "public class CashMachine extends JPanel {"
public class JPassword {
private String password = "pass";
private void main() {
//create frame
JFrame frame = new JFrame("Password");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(400,100);
JLabel label3 = new JLabel("Enter Pin Code");
JPanel panel = new JPanel();
frame.add(panel);
JPasswordField pass = new JPasswordField(5);
pass.setEchoChar('*');
pass.addActionListener(new AL());
panel.add(label3, BorderLayout.WEST);
panel.add(pass, BorderLayout.WEST);
}
private class AL implements ActionListener{
public void actionPerformed(ActionEvent e){
JPasswordField input = (JPasswordField) e.getSource();
char[] passy = input.getPassword();
String p = new String(passy);
if (p.equals(password)){
JOptionPane.showMessageDialog(null, "Correct");
}
else
JOptionPane.showMessageDialog(null, "Incorrect");
}
}
}
I've basically done that..
It's not throwing a hissy fit on bluej now, but i'll just finish off the code and see what happens.
Thank you for your help.