public class Rectangle extends JComponent { private int X; private int Y; private int SX; private int SY; private boolean shouldDraw; public Rectangle() { shouldDraw = false; X = 0; Y = 0; SX = 0; SY = 0; } public void SetX(int X) { this.X = X; } public void SetY(int Y) { this.Y = Y; } public void SetSX(int SX) { this.SX = SX; } public void SetSY(int SY) { this.SY = SY; } public void ShouldDraw(boolean shouldDraw) { this.shouldDraw = shouldDraw; } @Override protected void paintComponent(Graphics brush) { Graphics newBrush = brush.create(); if (this.isOpaque()) { newBrush.setColor(this.getBackground()); newBrush.fillRect(0, 0, this.getWidth(), this.getHeight()); } if (this.shouldDraw) { newBrush.setColor(new Color(0, 220, 255)); if (X < SX) { int buff = X; X = SX; SX = buff; } if (Y < SY) { int buff = Y; Y = SY; SY = buff; } } } }