// 15. Java Program to demonstrate MouseWheelMoved event.
import java.awt.Color;
import java.awt.Container;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JFrame;
import java.awt.*;
public class WheelEx2 extends JFrame
{
public WheelEx2()
{
final Container cPane = getContentPane();
MouseWheelListener mouseWheelListener = new MouseWheelListener()
{
Label lb=new Label();
public void mouseWheelMoved(MouseWheelEvent event)
{
lb.setBounds(20,50,100,20);
lb.setFont(new Font("Verdana", Font.BOLD, 18));
add(lb);
int direction=event.getWheelRotation();
if(direction<0)
lb.setText("UP");
else
lb.setText("Down");
}
};
cPane.addMouseWheelListener(mouseWheelListener);
cPane.setBackground(Color.GRAY);
cPane.setForeground(Color.RED);
}
public static void main(String args[])
{
JFrame jFrame = new WheelEx2();
jFrame.setSize(600, 400);
jFrame.setVisible(true);
}
}