CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: First applet

  1. #1
    Join Date
    Feb 2000
    Location
    Orlando, FL
    Posts
    13

    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();
    }

    }





  2. #2
    Join Date
    Dec 1999
    Location
    Chonghe, Taipei County, Taiwan, R.O.C.
    Posts
    231

    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
  •  





Click Here to Expand Forum to Full Width

Featured