CodeToad Forums » Java » does anyone know how I can create a password for my java netbeans application?
|
|
|
Hi, Iv made a small program but I would like to password it to gain extra marks. I'd like a message to show on opening the application inviting them to log in using their user details. Ideally a correct password should be required but it dosent really matter. At the moment I have come up with this code, but im not sure how to get it to work when the application is openend. If anyone can edit or tell me how to get it to pop up a password required message I'd be really greatful.
public class TestApp implements ActionListener {
JTextField textField;
public void actionPerformed(ActionEvent e) {
JButton button = (JButton)e.getSource();
String ac = button.getActionCommand();
if(ac.equals("log in"))
System.out.println("logging in..." + textField.getText());
// Verify name and password. If okay, you can
// show the next panel in a CardLayout. This
// next panel can have your display animation
// and controls on it.
}
private JPanel getContent() {
textField = new JTextField(12);
JButton logIn = new JButton("log in");
logIn.setActionCommand("log in");
logIn.addActionListener(this);
JPanel p = new JPanel();
p.add(new JLabel("name:"));
p.add(textField);
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("sign in", JLabel.CENTER), "North");
panel.add(p, "Center");
p = new JPanel();
p.add(logIn);
panel.add(p, "South");
return panel;
}
}
|
|
|
|
|
|
|
|
|
// |