Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
- Create an applet that takes Login Name and Password from the user and check that
- Login Name is "demo" and password is "demopassword".
- -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
- import java.applet.Applet;
- import java.awt.Button;
- import java.awt.Graphics;
- import java.awt.Label;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- /* <applet code = "Login" width= 200 height = 200>
- </applet>
- */
- public class Login extends Applet implements ActionListener
- {
- Label lblUser, lblPassword;
- TextField txtUser, txtPassword;
- Button bLogin;
- boolean blnCorrect;
- public void init()
- {
- lblUser = new Label("UserName");
- add(lblUser);
- txtUser = new TextField(20);
- add(txtUser);
- lblPassword = new Label("Password");
- add(lblPassword);
- txtPassword = new TextField(20);
- add(txtPassword);
- bLogin = new Button("Login");
- add(bLogin);
- bLogin.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e)
- {
- if(txtUser.getText().equals("demo") && txtPassword.getText().equals("demopassword"))
- blnCorrect = true;
- else
- blnCorrect = false;
- repaint();
- }
- public void paint(Graphics g)
- {
- if(blnCorrect)
- g.drawString("Successfully Logged in.", 50, 100);
- else
- g.drawString("Invalid username or password.", 50, 100);
- }
- }

Post new comment