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

Exercise 1. Write A Program To Change The Background Colour of Applet When User Performs Events Using Mause

The document describes a Java program that changes the background color of a frame window based on different mouse events. When the user presses the mouse, the background turns blue. When the user releases the mouse, the background turns red. When the mouse enters the window, the background turns orange, and when it exits, the background turns green. When the user clicks the mouse, the background turns cyan.

Uploaded by

Ganesh Ekambe
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)
136 views

Exercise 1. Write A Program To Change The Background Colour of Applet When User Performs Events Using Mause

The document describes a Java program that changes the background color of a frame window based on different mouse events. When the user presses the mouse, the background turns blue. When the user releases the mouse, the background turns red. When the mouse enters the window, the background turns orange, and when it exits, the background turns green. When the user clicks the mouse, the background turns cyan.

Uploaded by

Ganesh Ekambe
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

Name of Student: Ekambe Ganesh Roll No.

: 53
Experiment No.: 11 DOS:

Exercise
1. Write a program to change the background colour of Applet when
user performs events using mause

import java.awt.*;
import java.awt.event.*;
public class practical11_2 extends Frame implements MouseListener {
Label l;
String str;
practical11_2()
{ l = new
Label(); add(l);
addMouseListener(this);
setVisible(true);

setSize(400,400);
setLayout(new
FlowLayout());
}
public void mousePressed(MouseEvent e)
{
setBackground(Color.BLUE
); l.setText("BLUE");
}
public void mouseReleased(MouseEvent e)
{ setBackground(Color.red);
l.setText("RED");
}
public void mouseEntered(MouseEvent e) {
setBackground(Color.orange);
l.setText("ORANGE");
}
public void mouseExited(MouseEvent e)
{ setBackground(Color.green);
l.setText("Green");
}
public void mouseClicked(MouseEvent e)
{ setBackground(Color.CYAN);
l.setText("CYAN");
}
public static void main(String[] args)
{ new practical11_2();
}
}
Name of Student: Ekambe Ganesh Roll No.: 53
Experiment No.: 11 DOS:

Output :

You might also like