Program:-
a.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordA extends Applet implements ActionListener //Class Applet is //extended
using inheritance
{boolean clicked=false,code=false; // Boolean function is defined
Label passwordlabel = new Label(\"Password:\"); // object creation
TextField passwordfield = new TextField(15); // text field is assigned to the password
Button enterbutton = new Button(\"Enter\");
public void init() // initialization method is defined
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this); // button and password field is set
passwordlabel.setVisible(true);
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
clicked=true;
pass=passwordfield.getText();
if(pass.compareTo(\"Rosebud\")==0) // conditional statement is defined
code=true;
else
code=false;
repaint();
}
public void paint(Graphics g) //paint method is defined
{
if(clicked)
{if(code)
g.drawString(\"Access Granted\",120,150); // according to question.
else
g.drawString(\"Access Denied\",120,150);
}
}
}
b.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordB extends Applet implements ActionListener//Class Applet is //extended
using inheritance
{boolean clicked=false,code=false; // Boolean function is defined
Label passwordlabel = new Label(\"Password:\"); // object creation
TextField passwordfield = new TextField(15); // text field is assigned to the password
Button enterbutton = new Button(\"Enter\");
public void init()// initialization method is defined
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this);
passwordlabel.setVisible(true); // button and password field is set
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
clicked=true;
pass=passwordfield.getText();
if(pass.compareToIgnoreCase(\"Rosebud\")==0) // conditional statement is defined
code=true;
else
code=false;
repaint();
}
public void paint(Graphics g) //paint method is defined
{
if(clicked)
{if(code)
g.drawString(\"Access Granted\",120,150); // according to question.
else
g.drawString(\"Access Denied\",120,150);
}
}
}
c.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordC extends Applet implements ActionListener //Class Applet is //extended
using inheritance
{boolean clicked=false,code=false;
Label passwordlabel = new Label(\"Password:\"); // Boolean function is defined
TextField passwordfield = new TextField(15);
Button enterbutton = new Button(\"Enter\"); // object creation
public void init()// text field is assigned to the password
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this); // button and password field is set
p.
Program-a. library is importedimport java.awt.; import j.pdf
1. Program:-
a.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordA extends Applet implements ActionListener //Class Applet is //extended
using inheritance
{boolean clicked=false,code=false; // Boolean function is defined
Label passwordlabel = new Label("Password:"); // object creation
TextField passwordfield = new TextField(15); // text field is assigned to the password
Button enterbutton = new Button("Enter");
public void init() // initialization method is defined
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this); // button and password field is set
passwordlabel.setVisible(true);
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
clicked=true;
pass=passwordfield.getText();
if(pass.compareTo("Rosebud")==0) // conditional statement is defined
code=true;
else
code=false;
2. repaint();
}
public void paint(Graphics g) //paint method is defined
{
if(clicked)
{if(code)
g.drawString("Access Granted",120,150); // according to question.
else
g.drawString("Access Denied",120,150);
}
}
}
b.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordB extends Applet implements ActionListener//Class Applet is //extended
using inheritance
{boolean clicked=false,code=false; // Boolean function is defined
Label passwordlabel = new Label("Password:"); // object creation
TextField passwordfield = new TextField(15); // text field is assigned to the password
Button enterbutton = new Button("Enter");
public void init()// initialization method is defined
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this);
3. passwordlabel.setVisible(true); // button and password field is set
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
clicked=true;
pass=passwordfield.getText();
if(pass.compareToIgnoreCase("Rosebud")==0) // conditional statement is defined
code=true;
else
code=false;
repaint();
}
public void paint(Graphics g) //paint method is defined
{
if(clicked)
{if(code)
g.drawString("Access Granted",120,150); // according to question.
else
g.drawString("Access Denied",120,150);
}
}
}
c.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordC extends Applet implements ActionListener //Class Applet is //extended
using inheritance
{boolean clicked=false,code=false;
4. Label passwordlabel = new Label("Password:"); // Boolean function is defined
TextField passwordfield = new TextField(15);
Button enterbutton = new Button("Enter"); // object creation
public void init()// text field is assigned to the password
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this); // button and password field is set
passwordlabel.setVisible(true);
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
String pw[]={"Rosebud", "Redrum", "Jason", "Surrender","Dorothy"};
clicked=true;
pass=passwordfield.getText();
code=false;
for(int i=0;i<5;i++)
if(pass.compareToIgnoreCase(pw[i])==0) // conditional statement is defined
code=true;
repaint();
}
public void paint(Graphics g) //paint method is defined
{
if(clicked)
5. {if(code)
g.drawString("Access Granted",120,150); // according to question.
else
g.drawString("Access Denied",120,150);
}
}
}
Solution
Program:-
a.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordA extends Applet implements ActionListener //Class Applet is //extended
using inheritance
{boolean clicked=false,code=false; // Boolean function is defined
Label passwordlabel = new Label("Password:"); // object creation
TextField passwordfield = new TextField(15); // text field is assigned to the password
Button enterbutton = new Button("Enter");
public void init() // initialization method is defined
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
6. enterbutton.addActionListener(this); // button and password field is set
passwordlabel.setVisible(true);
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
clicked=true;
pass=passwordfield.getText();
if(pass.compareTo("Rosebud")==0) // conditional statement is defined
code=true;
else
code=false;
repaint();
}
public void paint(Graphics g) //paint method is defined
{
if(clicked)
{if(code)
g.drawString("Access Granted",120,150); // according to question.
else
g.drawString("Access Denied",120,150);
}
}
}
b.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordB extends Applet implements ActionListener//Class Applet is //extended
using inheritance
{boolean clicked=false,code=false; // Boolean function is defined
7. Label passwordlabel = new Label("Password:"); // object creation
TextField passwordfield = new TextField(15); // text field is assigned to the password
Button enterbutton = new Button("Enter");
public void init()// initialization method is defined
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this);
passwordlabel.setVisible(true); // button and password field is set
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
clicked=true;
pass=passwordfield.getText();
if(pass.compareToIgnoreCase("Rosebud")==0) // conditional statement is defined
code=true;
else
code=false;
repaint();
}
public void paint(Graphics g) //paint method is defined
{
if(clicked)
{if(code)
g.drawString("Access Granted",120,150); // according to question.
else
g.drawString("Access Denied",120,150);
}
}
8. }
c.
// library is imported
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordC extends Applet implements ActionListener //Class Applet is //extended
using inheritance
{boolean clicked=false,code=false;
Label passwordlabel = new Label("Password:"); // Boolean function is defined
TextField passwordfield = new TextField(15);
Button enterbutton = new Button("Enter"); // object creation
public void init()// text field is assigned to the password
{
add(passwordlabel);
add(passwordfield);
add(enterbutton);
enterbutton.addActionListener(this); // button and password field is set
passwordlabel.setVisible(true);
passwordfield.setVisible(true);
}
public void actionPerformed(ActionEvent e) // method
{ String pass;
String pw[]={"Rosebud", "Redrum", "Jason", "Surrender","Dorothy"};
clicked=true;