0% found this document useful (0 votes)
8 views9 pages

Ajp Exp 12

Advance java experiment 12 msbte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Ajp Exp 12

Advance java experiment 12 msbte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

NAME : Mujahid Chaudhary

Roll No: 230482

Experiment No : 12

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class exp12_1 extends JFrame implements ActionListener {

JPasswordField j;

JLabel l1, l2, l3;

JTextField t1;

JButton b1, b2;

exp12_1() {

setLayout(new GridLayout(4, 2));

setTitle("MM");

l1 = new JLabel("Enter username: ");

l2 = new JLabel("Enter password: ");

t1 = new JTextField(10);

j = new JPasswordField(10);

l3 = new JLabel(" ");

b1 = new JButton("Login");

b2 = new JButton("Reset");

b1.addActionListener(this);

b2.addActionListener(this);

add(l1); add(t1);

add(l2); add(j);

add(b1); add(b2);

add(l3); setSize(400, 400);

setVisible(true);

public void actionPerformed(ActionEvent e) {

if (e.getSource() == b1) {

if (t1.getText().equals("<your_username>") && j.getText().equals("<your_password>"))


NAME : Mujahid Chaudhary

Roll No: 230482

l3.setText("Valid Login");

else l3.setText("Invalid Login");

else if (e.getSource() == b2) {

t1.setText(" ");

j.setText(" ");

l3.setText(" ");

public static void main(String a[]){


NAME : Mujahid Chaudhary

Roll No: 230482

new exp12_1();}}
NAME : Mujahid Chaudhary

Roll No: 230482

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class exp12_2 extends JFrame implements ActionListener

JPasswordField j;

JLabel l1, l2, l3;

JTextField t1;

JButton b1, b2;

exp12_2() {

setLayout(new GridLayout(4, 2));

setTitle("MM");

l1 = new JLabel("Enter username: ");

l2 = new JLabel("Enter password: ");

t1 = new JTextField(10);

j = new JPasswordField(10);

l3 = new JLabel(" ");

b1 = new JButton("Login");

b2 = new JButton("Reset");

b1.addActionListener(this);

b2.addActionListener(this);

add(l1);

add(t1);

add(l2);

add(j);

add(b1);

add(b2);

add(l3);

setSize(400, 400);

setVisible(true);
NAME : Mujahid Chaudhary

Roll No: 230482

@SuppressWarnings("deprecation")

public void actionPerformed(ActionEvent e) {

if (e.getSource() == b1) {

if (t1.getText().equals("mhssp") && j.getText().length()<6)

l3.setText("Password length must be greater than 6 characters");

else

l3.setText("Valid Password");

else if (e.getSource() == b2) {

t1.setText(" ");

j.setText(" ");

l3.setText(" ");

public static void main(String a[]) {

new exp12_2();}}
NAME : Mujahid Chaudhary

Roll No: 230482

import javax.swing.*;

import java.awt.*;

public class exp12_3 extends JFrame

JLabel l1;

JPasswordField pf1;

exp12_3()

setLayout(new FlowLayout());

l1=new JLabel("Enter the Password");

pf1=new JPasswordField(10);

pf1.setEchoChar('#');

add(l1);

add(pf1);

setVisible(true);

setTitle("MM");

setSize(100,100);
NAME : Mujahid Chaudhary

Roll No: 230482

public static void main(String []args)

new exp12_3();

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class exp12_4 extends JFrame implements ActionListener {

JLabel l1,l2,l3;

JTextField t1,t2,t3;

JButton b1,b2;

exp12_4() {

setLayout(new GridLayout(4,2));

setTitle("MM");

l1=new JLabel("Enter the first number:");

t1=new JTextField(10);

l2=new JLabel("Enter the second number:");

t2=new JTextField(10);

l3=new JLabel("Addition of number's is:");

t3=new JTextField(10);

b1=new JButton("Add");
NAME : Mujahid Chaudhary

Roll No: 230482

b1.addActionListener(this);

b2=new JButton("Clear");

b2.addActionListener(this);

add(l1); add(t1);

add(l2);

add(t2);

add(l3);

add(t3);

add(b1);

add(b2);

setVisible(true);

setSize(100,100);

public void actionPerformed(ActionEvent e) {

if (e.getSource()==b1) {

int c=Integer.parseInt(t1.getText());

int d=Integer.parseInt(t2.getText());

int a=c+d;

t3.setText(Integer.toString(a));

if (e.getSource()==b2) {

t1.setText(" ");

t2.setText(" ");

t3.setText(" ");

public static void main(String []args) {

new exp12_4();

}
NAME : Mujahid Chaudhary

Roll No: 230482

You might also like