How do i create a method to do something continuous when i press a key and make it stop when i press a different key? thanks
String myKey = Greenfoot.getKey(); if (myKey != null) lastKeyPressed = myKey; if ("4".equals(lastKeyPressed)) { Color a; int r = Greenfoot.getRandomNumber(255); int g = Greenfoot.getRandomNumber(255); int b = Greenfoot.getRandomNumber(255); int x = Greenfoot.getRandomNumber(this.getWidth()); int y = Greenfoot.getRandomNumber(this.getHeight()); int x1 = Greenfoot.getRandomNumber(this.getWidth() - x); int y2 = Greenfoot.getRandomNumber(this.getHeight() - y); a = new Color(r, g, b, 255); background.clear(); background.setColor(a); background.drawRect(x, y, x1, y2); }