This repository was archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarChartComponent.java
More file actions
76 lines (62 loc) · 2.09 KB
/
Copy pathBarChartComponent.java
File metadata and controls
76 lines (62 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.awt.*;
import javax.swing.*;
/**
* Defines a component which displays a bar chart
* of referee match allocations. Each bar is identified
* by the corresponding referee's ID, and the number of
* match allocations is displayed above each bar.
* @author Adam John Campbell Murray
*
*/
@SuppressWarnings("serial")
public class BarChartComponent extends JComponent
{
/* Instance variables */
// Object instance variables
private RefereeProgram refereeProgram;
/**
* Constructor for BarChartComponent.
* @param rProg - RefereeProgram being used
*/
public BarChartComponent(RefereeProgram rProg)
{
refereeProgram = rProg;
}
public void paintComponent(Graphics g)
{
// recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
// add string to top left hand corner of component
g2.drawString("(Number of match allocations above each bar)", 10, 20);
// initialise top left hand corner coordinates,
// and width of the bar chart bars
int barXCoord = 10;
int barYCoord = 200;
int barWidth = 60;
// add a bar for each referee
for (int x = 0; x < refereeProgram.getelementsInArray(); x++)
{
RefereeClass refAtX = refereeProgram.getRefereeClassAtX(x);
// set colour of the bar chart outline
g2.setColor(Color.BLACK);
// draw outline of bars
g2.draw(new Rectangle(barXCoord, barYCoord - (refAtX.getAllocatedMatches() * 10),
barWidth, (refAtX.getAllocatedMatches() * 10)));
// set colour of the bar chart bars
g2.setColor(Color.RED);
// fill bars
g2.fill(new Rectangle(barXCoord, barYCoord - (refAtX.getAllocatedMatches() * 10),
barWidth, (refAtX.getAllocatedMatches() * 10)));
// set colour of the ID identifiers
g2.setColor(Color.BLACK);
// draw match allocations about each bar
g2.drawString(refereeProgram.getRefereeClassAtX(x).getRefereeID(),
barXCoord + 20, barYCoord + 20);
// draw bar identifiers
g2.drawString("" + refereeProgram.getRefereeClassAtX(x).getAllocatedMatches(),
barXCoord + 25, barYCoord - (refAtX.getAllocatedMatches() * 10) - 5);
// increment x-coord of bars
barXCoord += 70;
}
}
}