How do I check if the user is pressing a key?

In java you don’t check if a key is pressed, instead you listen to KeyEvents. The right way to achieve your goal is to register a KeyEventDispatcher, and implement it to maintain the state of the desired key: import java.awt.KeyEventDispatcher; import java.awt.KeyboardFocusManager; import java.awt.event.KeyEvent; public class IsKeyPressed { private static volatile boolean wPressed = false; … Read more

Resource leak: ‘in’ is never closed

Why does Eclipse give me the warming “Resource leak: ‘in’ is never closed” in the following code? public void readShapeData() { Scanner in = new Scanner(System.in); System.out.println(“Enter the width of the Rectangle: “); width = in.nextDouble(); System.out.println(“Enter the height of the Rectangle: “); height = in.nextDouble();