0% found this document useful (0 votes)
83 views

MSBTE Solution App-1

The document contains two Java programs. The first program changes the background color when the user drags or moves the mouse. The second program counts and displays the number of mouse clicks in a frame window.

Uploaded by

Ashish Khillare
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)
83 views

MSBTE Solution App-1

The document contains two Java programs. The first program changes the background color when the user drags or moves the mouse. The second program counts and displays the number of mouse clicks in a frame window.

Uploaded by

Ashish Khillare
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/ 2

Experiment No.

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.*;

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>
*/

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();
}
}

You might also like