|
-
February 29th, 2000, 08:46 PM
#1
First applet
I have to create an applet that asks the user for a passwwd that needs to match "steak". When the user enters the passwd it returns the message access is denied no matter what password is entered. Can some tell me what is wrong?
This is my code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Password2a extends Applet implements ActionListener
{
static final public String PASSWORD = "steak";
Label question = new Label("Please enter the password.");
Font bigFont = new Font("Courier", Font.BOLD,20);
Button Enter = new Button("Enter");
TextField password = new TextField(" ",10);
public void init()
{
question.setFont(bigFont);
add(question);
add(password);
add(Enter);
Enter.addActionListener(this);
password.addActionListener(this);
password.requestFocus();
}
public void actionPerformed(ActionEvent Enter)
{
String name = password.getText();
Label newPassword = new Label (" ");
if (name == PASSWORD)
newPassword.setText("Access Granted");
else
newPassword.setText("Access Denied");
add(newPassword);
invalidate();
validate();
}
}
-
March 1st, 2000, 04:34 AM
#2
Re: First applet
you may try this way :
if(name.equals(PASSWORD)) {
}
else {
}
instead the instruction , if(name==PASSWORD)
good luck
Alfred Wu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|