how to fox an object not to move out of frame in java :  Fix this code in such way that rectangle does not move out of frame bounds
frame size is (400,400)

 public void moveRectangle(int dx, int dy) {
        rect.translate(dx * RECT_WIDTH, dy * RECT_HEIGHT);

        repaint();
    }