Rectangle r = new Rectangle(Math.min(prevX, x), Math.min(prevY, y), Math.abs(x - prevX), Math.abs(y - prevY)); g.drawRect(r.x, r.y, r.width, r.height); Color c = new Color(228, 228, 205); g.setPaint(c); g.fill(r); g.setPaint(Color.BLACK); g.draw(r); rect = r;
if (prevX != x && prevY != y) { Rectangle r = new Rectangle(Math.min(prevX, x), Math.min(prevY, y), Math.abs(x - prevX), Math.abs(y - prevY)); g.drawRect(r.x, r.y, r.width, r.height); Color c = new Color(228, 228, 205); g.setPaint(c); g.fill(r); g.setPaint(Color.BLACK); g.draw(r); rect = r; }
	public void mouseDragged(MouseEvent evt) {		if (dragging == false)			return;		int x = Math.min(evt.getX(), getSize().width - 1);		x = Math.max(x, 0);		int y = Math.min(evt.getY(), getSize().height - 1);		y = Math.max(y, 0);		paintComponent(g);		Rectangle r = new Rectangle(Math.min(prevX, x), Math.min(prevY, y),				Math.abs(x - prevX), Math.abs(y - prevY));		g.drawRect(r.x, r.y, r.width, r.height);		Color c = new Color(228, 228, 205);		g.setPaint(c);		g.fill(r);		g.setPaint(Color.BLACK);		g.draw(r);		rect = r;	}