0% found this document useful (0 votes)
19 views12 pages

Ajp Prac 11

Uploaded by

saeedarwatkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views12 pages

Ajp Prac 11

Uploaded by

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

Practical No.

11
 Program code: Debug the following code and write the output.
import java.awt.*;

import java.applet.*;

import java.awt.event.*;

/*<applet code="saee_11_1" width=500 height=500></applet>*/

public class saee_11_1 extends Applet implements MouseListener

Label l;

public void init()

setLayout(null);

l=new Label("Hello Mouse");

l.setBounds(50,150,200,100);

add(l);

public void mousePressed(MouseEvent e)

l.setText("Mouse Pressed no. of Clicks:" +e.getClickCount()+ "at position:" +e.getX()+","+e.getY());

public void mouseReleased(MouseEvent e)

l.setText("Mouse Released; # of clicks:"+e.getClickCount());


}

public void mouseEntered(MouseEvent e)

l.setText("Mouse Entered");

public void mouseExited(MouseEvent e)

l.setText("Mouse Exited");

public void mouseClicked(MouseEvent e)

l.setText("Mouse Clicked; # of clicks:"+e.getClickCount());

Output:
 Exercise:

1) Write a program to change the background color of Applet when user performs events
using Mouse.

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

/*<applet code="saee_11_2" width=500 height=500></applet>*/

public class saee_11_2 extends Applet implements MouseListener

Label l;

public void init()

setLayout(null);

l=new Label();

l.setBounds(50,150,200,100);

add(l);

addMouseListener(this);

public void mousePressed(MouseEvent e)

l.setText("MOUSE PRESSED");

setBackground(Color.red);

repaint();

}
public void mouseReleased(MouseEvent e)

l.setText("MOUSE RELEASED");

setBackground(Color.pink);

repaint();

public void mouseEntered(MouseEvent e)

l.setText("MOUSE ENTERED");

setBackground(Color.yellow);

repaint();

public void mouseExited(MouseEvent e)

l.setText("MOUSE EXITED");

setBackground(Color.green);

repaint();

public void mouseClicked(MouseEvent e)

l.setText("MOUSE CLICKED");

setBackground(Color.blue);

repaint();

}
}

Output:
2) Write a program to count the number of clicks performed by the user in a
Frame Window.
import java.awt.*;

import java.awt.event.*;

public class saee_11_3 implements MouseListener

Label l;

Frame f=new Frame("saee_11_3");

saee_11_3()

f.setVisible(true);

f.setSize(500,500);

f.setLayout(new FlowLayout());

l=new Label();

f.add(l);

f.addMouseListener(this);

public void mousePressed(MouseEvent me)

{}

public void mouseReleased(MouseEvent me)

{}

public void mouseClicked(MouseEvent me)

{
l.setText("Number of clicks:"+ me.getClickCount());

public void mouseEntered(MouseEvent me)

{}

public void mouseExited(MouseEvent me)

{}

public static void main(String args[])

saee_11_3 obj=new saee_11_3();

Output:
3) Write a program to demonstrate the use of mouseDragged and
mouseMoved method of MouseMotionlListener.

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

/*<applet code="saee_11_4" width=500 height=500></applet>*/

public class saee_11_4 extends Applet implements MouseMotionListener

Label l;

public void init()

l=new Label();

add(l);

addMouseMotionListener(this);

public void mouseMoved(MouseEvent me)

l.setText("X:"+me.getX()+","+"Y:"+me.getY());

public void mouseDragged(MouseEvent me)

l.setText("X:"+me.getX()+","+"Y:"+me.getY());

Graphics g=getGraphics();
g.setColor(Color.blue);

g.fillOval(me.getX(),me.getY(),5,5);

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