List of usage examples for java.awt Container addMouseWheelListener
public synchronized void addMouseWheelListener(MouseWheelListener l)
From source file:MouseWheelTest.java
public MouseWheelTest() { super();//from www . ja va 2 s .com final Container contentPane = getContentPane(); MouseWheelListener listener = new MouseWheelListener() { int colorCounter; private static final int UP = 1; private static final int DOWN = 2; public void mouseWheelMoved(MouseWheelEvent e) { int count = e.getWheelRotation(); int direction = (Math.abs(count) > 0) ? UP : DOWN; changeBackground(direction); } private void changeBackground(int direction) { contentPane.setBackground(colors[colorCounter]); if (direction == UP) { colorCounter++; } else { --colorCounter; } if (colorCounter == colors.length) { colorCounter = 0; } else if (colorCounter < 0) { colorCounter = colors.length - 1; } } }; contentPane.addMouseWheelListener(listener); }