Skip to content

Commit

Permalink
fixed array not drawing properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hugh5 committed Nov 23, 2022
1 parent 6f3aeab commit ae16218
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MainWindow implements ActionListener, ChangeListener {
private final JFrame window;
private MenuPanel menuPanel;
private SortingPanel sortingPanel;
public static final int MAX = 383;
public static final int MAX = 256;
public static final int MIN = 1;

private final Logger logger = Logger.getLogger(this.getClass().getName());
Expand Down
10 changes: 6 additions & 4 deletions src/SortingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ public SortingPanel() {
}

public void paint(Graphics g) {
int y = getHeight() - 20;
int scalar = getHeight() / max;
int width = Math.min(getWidth() / array.length, 100);
g.setFont(new Font("Monospaced", Font.PLAIN, 16));
for (int i = 0; i < array.length; i++) {
g.setColor(map.get(i));
g.fillRect(i * width, y, width - 1, -scalar * array[i]);
g.setColor(Color.BLACK);
// g.drawString(String.valueOf(array[i]), i * width + width / 4, y + 15);
g.setColor(map.get(i));
g.fillRect(i * width, getHeight() - scalar * array[i], width - 1, scalar * array[i]);
if (width >= 24) {
g.setColor(Color.WHITE);
g.drawString(String.valueOf(array[i]), i * width + width / 4, getHeight() - 5);
}
}
}

Expand Down

0 comments on commit ae16218

Please sign in to comment.