How Can you check, if the mouse has been scrolled?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import greenfoot.core.WorldHandler; import java.awt.event.*; public class world extends World { ScrollingListener scroll= new ScrollingListener(); int Scroll = 0 ; public world() { super ( 500 , 400 , 1 , false ); WorldHandler.getInstance().getWorldCanvas().addMouseWheelListener(scroll); } public void act() { Scroll+=scroll.getScroll(); } } class ScrollingListener implements MouseWheelListener { int scroll = 0 ; public void mouseWheelMoved(MouseWheelEvent MWE) { scroll+=MWE.getWheelRotation(); MWE.consume(); } public int getScroll() { int a=scroll; scroll= 0 ; return a; } } |
1 2 3 | int a=scroll; scroll= 0 ; return a; |
1 2 3 4 | if (scroll.getScroll()!= 0 ) { System.out.println(scroll.getScroll()); } |
1 2 3 4 5 | int s=scroll.getScroll(); if (s!= 0 ) { System.out.println(s); } |
1 2 3 4 5 6 7 8 9 10 | private int scrollValue; private int scrollHiLimit = 15 ; private int scrollLoLimit = 0 ; // public void act() { scrollValue += scroll.getScroll(); if (scrollValue > scrollHiLimit) { scrollValue = scrollHiLimit; } if (scrollValue < scrollLoLimit) { scrollValue = scrollLoLimit; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class ScrollingListener implements MouseWheelListener { int scroll = 0 ; public synchronized void mouseWheelMoved(MouseWheelEvent MWE) { scroll+=MWE.getWheelRotation(); MWE.consume(); } public synchronized int getScroll() { int a=scroll; scroll= 0 ; return a; } } |