Skip to content

Commit 92261c2

Browse files
Added Array Visualization
1 parent 86ba0ff commit 92261c2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/DrawRect.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.awt.*;
2+
import javax.swing.*;
3+
import java.util.ArrayList;
4+
import java.util.Random;
5+
6+
public class DrawRect extends JPanel {
7+
8+
public static final int HEIGHT = 900;
9+
public static final int WIDTH = 30;
10+
public static final Color RECT_COLOR = new Color(135, 206, 235);
11+
12+
ArrayList<Integer> arr;
13+
14+
public DrawRect(ArrayList<Integer> heights) {
15+
// Deep Cloning
16+
arr = new ArrayList<>();
17+
for (int i = 0; i < heights.size(); i++)
18+
arr.add(heights.get(i));
19+
}
20+
21+
@Override
22+
public void paintComponent(Graphics g) {
23+
Graphics2D graphics = (Graphics2D) g;
24+
super.paintComponent(graphics);
25+
for (int i = 0, x = 5; x <= 1600; x += WIDTH + 5, i++) {
26+
int y = arr.get(i);
27+
graphics.setColor(RECT_COLOR);
28+
graphics.fillRect(x, y, WIDTH, HEIGHT);
29+
}
30+
}
31+
}
File renamed without changes.

0 commit comments

Comments
 (0)