Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Create an applet that takes Login Name and Password from the user and check them

  1. /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  2. Create an applet that takes Login Name and Password from the user and check that
  3. Login Name is "demo" and password is "demopassword".
  4. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
  5. import java.applet.Applet;
  6. import java.awt.Button;
  7. import java.awt.Graphics;
  8. import java.awt.Label;
  9. import java.awt.TextField;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. /*   <applet code = "Login" width= 200 height = 200>
  13.  </applet>
  14. */
  15. public class Login extends Applet implements ActionListener
  16. {
  17.  Label lblUser, lblPassword;
  18.  TextField txtUser, txtPassword;
  19.  Button bLogin;
  20.  boolean blnCorrect;
  21.  
  22.  public void init()
  23.  {
  24.   lblUser = new Label("UserName");
  25.   add(lblUser);
  26.  
  27.   txtUser = new TextField(20);
  28.   add(txtUser);
  29.  
  30.   lblPassword = new Label("Password");
  31.   add(lblPassword);
  32.  
  33.   txtPassword = new TextField(20);
  34.   add(txtPassword);
  35.  
  36.   bLogin = new Button("Login");
  37.   add(bLogin);
  38.   bLogin.addActionListener(this);
  39.  }
  40.  
  41.  public void actionPerformed(ActionEvent e)
  42.  {
  43.   if(txtUser.getText().equals("demo") && txtPassword.getText().equals("demopassword"))
  44.    blnCorrect = true;
  45.   else
  46.    blnCorrect = false;
  47.  
  48.   repaint();
  49.  }
  50.  
  51.  public void paint(Graphics g)
  52.  {
  53.  
  54.   if(blnCorrect)
  55.    g.drawString("Successfully Logged in.", 50, 100);
  56.   else
  57.    g.drawString("Invalid username or password.", 50, 100);
  58.  }
  59. }
Your rating: None Average: 4.5 (2 votes)
Share this

Post new comment

13 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.