Skip to content

Commit 839771f

Browse files
Fixed first swap not showing
1 parent 0d67bcd commit 839771f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/DrawRect.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ public class DrawRect extends JPanel {
1111
ArrayList<Integer> arr;
1212

1313
public DrawRect(ArrayList<Integer> heights) {
14+
// Shallow Cloning
1415
arr = heights;
1516
}
17+
18+
// Changing the instance variable so that paint component is called
1619
public void setArr(ArrayList<Integer> newArr) {
1720
arr = newArr;
18-
}
21+
}
22+
1923
@Override
2024
public void paintComponent(Graphics g) {
2125
Graphics2D graphics = (Graphics2D) g;
2226
super.paintComponent(graphics);
2327
graphics.setColor(RECT_COLOR);
24-
for (int i = 0, x = 5; x <= 1600; x += WIDTH + 5, i++) {
28+
for (int i = 0, x = 10; x <= 1580; x += WIDTH + 4, i++) {
2529
int y = arr.get(i);
2630
graphics.fillRect(x, y, WIDTH, HEIGHT);
2731
}

0 commit comments

Comments
 (0)