Ayush Practical No 11
Ayush Practical No 11
Ayush Practical No 11
X. Program Code.
1. Debug The Following Program Code And Write The Output.
Code :-
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
Label l;
setLayout(null);
l.setBounds(50,150,200,100);
add(l);
1
}
l.setText("Mouse Entered");
l.setText("Mouse Exited");
2
Output :-
XIII. Exercise.
setLayout(new FlowLayout());
setSize(600,600);
setVisible(true);
3
addMouseListener(this);
add(t);
}
public static void main(String args[])
{ new MouseExample1();
}
@Override
public void mouseClicked(MouseEvent e) {
@Override
public void mousePressed(MouseEvent e) {
@Override
public void mouseReleased(MouseEvent e) {
@Override
public void mouseEntered(MouseEvent e) {
@Override
public void mouseExited(MouseEvent e) {
}
}
4
Output :-
import java.awt.*;
import java.awt.event.*;
public class MouseListenerEx1 extends Frame implements
MouseListener{
Label L;
MouseListenerEx1(){
addMouseListener(this);
5
L=new Label();
L.setBounds(25,55,130,25);
add(L);
setSize(300,350);
setLayout(null);
setVisible(true);
}
public void mouseClicked(MouseEvent e) {
L.setText("Mouse Clicked "+e.getClickCount());
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public static void main(String[] args) {
new MouseListenerEx1();
}
}
Output :-
6
4. Write a Program To Demonstrate The Use Of MouseDragged And
MouseMoved Method Of MouseMotionListener.
Code :-
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MouseMotionExample2 extends JFrame
implements MouseMotionListener{
JTextArea T1=new JTextArea("Move your mouse here
",35,25);
JTextArea T2=new JTextArea("Drag your mouse
here",35,25);
MouseMotionExample2()
{
setLayout(new FlowLayout());
7
setSize(600,600);
setVisible(true);
addMouseMotionListener(this);
add(T1);
add(T2);
}
public void mouseMoved(MouseEvent e)
{
T1.setText("Mouse is Moving\n Position Of Mouse Is At :
"+ e.getX()+" "+e.getY());
}
8
Output :-