MSBTE Solution App-1
MSBTE Solution App-1
11
Write a program to change the background color of applet when user performs events using
Mouse.
Write a program to demonstrate the use of mouseDragged and mouseMoved method of
MouseMotionListener.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
}
/*
<applet code="MouseColor" width=300 height=300>
</applet>
*/
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 MouseListenerExample extends Frame implements MouseListener{
Label l;
MouseListenerExample(){
addMouseListener(this);
l=new Label();
l.setBounds(20,50,100,20);
add(l);
setSize(300,300);
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 MouseListenerExample();
}
}