Hi.
I can get the Button that is clicked with mouse.getButton(), but how do i get it when the button goes up again, so it will only go into an if() if the button is released, you know what i mean?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public void act() { MouseInfo m = Greenfoot.getMouseInfo(); if (m != null ) checkClick(m); } private void checkClick(MouseInfo m) { if (m.getButton() == 1 ) //left-click { while (m.getButton() != 0 ); //This is more than likely the worst way to wait, but it's what came into my head at the time :) //Your left-click code here } else if (m.getButton() == 3 ) //right-click { while (m.getButton() != 0 ); //Your right-click code here } } |
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 | import greenfoot.*; public class Buttons extends World { final int btnNONE = 0 , btnLEFT = 1 , btnRIGHT = 3 ; public Buttons() { super ( 800 , 600 , 1 ); } public void act() { MouseInfo mi = Greenfoot.getMouseInfo(); if (Greenfoot.mousePressed( null )) { int button = mi.getButton(); if (button == btnLEFT) System.out.println( "Left" ); if (button == btnRIGHT) System.out.println( "Right" ); } if (Greenfoot.mouseClicked( null )) { int button = mi.getButton(); if (button == btnLEFT) System.out.println( "No left" ); if (button == btnRIGHT) System.out.println( "No right" ); } } } |
1 2 3 4 5 | if (mouse != null && mouse.getButton() == 3 && !Greenfoot.mouseDragEnded( this )) { item_rotation++; if (item_rotation == 4 )item_rotation = 0 ; } |
1 2 3 4 5 | if (mouse != null && mouse.getButton() == 3 && !Greenfoot.mouseDragEnded( this )) { item_rotation++; if (item_rotation == 4 )item_rotation = 0 ; } |
1 | if (Greenfoot.mouseClicked( this ) && !Greenfoot.mouseDragEnded( this ) && Greenfoot.getMouseInfo().getButton() == 3 ) |