Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

my 1st applet....problem!  RSS feed

 
deb uebersetzig
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my applet is always saying access denied....what is wrong....
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Password extends Applet implements ActionListener
{
Label password = new Label("Enter your password");
TextField answer = new TextField("", 10);
public void init()
{
add(password);
add(answer);
answer.addActionListener(this);
answer.requestFocus();
}
public void actionPerformed(ActionEvent e)
{
String reply = answer.getText();
Label theOK = new Label("");
if(reply == "Rosebud")
{
theOK.setText("Access Granted");
add(theOK);
remove(answer);
invalidate();
validate();
}
else if(reply != "Rosebud")
{
theOK.setText("Access Denied");
add(theOK);
remove(answer);
invalidate();
validate();
}
}
}
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deb,
The problem was the method used to compare the correct password to what the user entered. Make the changes shown below and it should work fine.

Hope this helps.
If not, let us know.
Stephanie
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!