AJP Pract-11 - Merged

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Practical No.

11:- Write a program to demonstrate various mouse events


using MouseListener and MouseMotion Listener interface.
Code-1:

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class MouseColor extends Applet implements MouseMotionListener

public void init()

addMouseMotionListener(this);

public void mouseDragged(MouseEvent me)

setBackground(Color.red);

repaint();

public void mouseMoved(MouseEvent me)

setBackground(Color.green);

repaint();

/*

<applet code="MouseColor" width=300 height=300>

</applet>

*/
Output:

Code-2:

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class MouseCount extends Applet implements MouseListener

int count = 0;

public void init()

addMouseListener(this);

}
public void mouseClicked(MouseEvent me)

count++;

showStatus("Number of time Clicked:"+count);

repaint();

public void mouseEntered(MouseEvent me)

public void mouseExited(MouseEvent me)

public void mousePressed(MouseEvent me)

public void mouseReleased(MouseEvent me)

/*

<applet code="MouseCount" width=300 height=300>

</applet>

*/

Output:
Code-3:

import java.awt.*;

import java.awt.event.*;

public class MouseListenerEx extends Frame implements MouseListener

Label l;

MouseListenerEx()

addMouseListener(this);

l=new Label();

l.setBounds(20,50,100,200);
add(l);

setSize(300,300);

setLayout(null);

setVisible(true);

public void mouseClicked(MouseEvent e)

l.setText("Mouse Clicked");

public void mouseEntered(MouseEvent e)

l.setText("Mouse Entered");

public void mouseExited(MouseEvent e)

l.setText("Mouse Exited");

public void mousePressed(MouseEvent e)

l.setText("Mouse Pressed");

public void mouseReleased(MouseEvent e)

l.setText("Mouse Released");

public static void main(String[] args)


{

new MouseListenerEx();

Output:
Practical No 12: write a program to demonstrate the use of JTextField and
JPasswordField using Listener Interface.

import javax.swing.*;

import java.awt.*;

public class JPasswordChange

public static void main(String[] args) {

JFrame f = new JFrame();

f.setVisible(true);

f.setSize(400,400);

f.setLayout(new FlowLayout());

JPasswordField pf = new JPasswordField(20);

pf.setEchoChar('#');

f.add(pf);

OUTPUT:
Write a Program Using JPasswordField And JTextField To Demonstrate The UseOf
User Authetication.

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class PasswordFieldExample1

{ public static void main(String[] args)

{JFrame F=new JFrame("Password Field Example");

final JLabel label = new JLabel();

label.setBounds(20,150, 200,50);

final JPasswordField value = new JPasswordField();

value.setBounds(100,75,100,30);

JLabel L1=new JLabel("Username:");

L1.setBounds(20,20, 80,30);

JLabel L2=new JLabel("Password:");

L2.setBounds(20,75, 80,30);

JButton B = new JButton("Login");

B.setBounds(100,120, 80,30);

final JTextField text = new JTextField();

text.setBounds(100,20, 100,30);

F.add(value);

F.add(L1);

F.add(label);

F.add(L2);
F.add(B);

F.add(text);

F.setSize(300,350);

F.setLayout(null);

F.setVisible(true);

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy