nelson ruiz
Posts: 7
Nickname: nogal
Registered: Mar, 2008
password
Posted: Apr 12, 2008 10:35 PM
Advertisement
Hi. I am doing a JApplet where I ask the user to enter a password to a JTextField and then press ENTER. Compare it with the word "Rosebud", if it matches exactly, display "Access Granted", if not, display "Access Denied". I haven't found the way to compare the input and the password. Could somebody help me.... Thanks import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JHello extends JApplet implements ActionListener { Container con = getContentPane (); JLabel please = new JLabel ("Please Enter password"); Font headlineFont = new Font("Helvetica", Font.BOLD, 36); JTextField answer = new JTextField (10); JButton pressMe = new JButton("Click Here"); JLabel passtyped = new JLabel (""); String password = "Rosebud"; public void init() { please.setFont(headlineFont); con.add(please); con.add(answer); con.add(pressMe); con.setLayout(new FlowLayout()); pressMe.addActionListener(this); answer.addActionListener(this); } public boolean action(Event e) { if ( answer.equals ( password ) ) { s = null; } else { s = "Access Denied"; repaint(); } return true; } public void actionPerformed(ActionEvent e) { String name = answer.getText(); passtyped.setText("Access granted"); con.add(passtyped); validate(); } }