import java.awt.BorderLayout; import java.awt.Font; import java.awt.Graphics; /** * * Class DetailedStats. This class will give a statistical information * via a graphic demonstrating how much time the ball has spent in each * third of the pitch. The data is calculated by the Stats class and is * passed to this object every second. The class extends PitchPanel which * carries out all the rendering of the pitch jpeg. * * @author Adrien Martel * */ public class DetailedStats extends PitchPanel{ Font font; String t0 = "0%"; String t1 = "0%"; String t2 = "0%"; boolean firstHalf = true; /** * Constructor DetailedStats. Calls the its superclass to render the * pitch * */ public DetailedStats(){ super("pitchSplit.jpg"); font = new Font("lucida sans demibold", Font.BOLD, 24); f.add(this); f.setSize(305,203); f.setVisible(true); f.setTitle("Cumulative Ball Distribution Window"); paintAll(); } /** * Method changeOver. Changes to second half mode. ie the stats are reset * and the percentages switched. * */ public void changedOver(){ firstHalf = false; } /** * updateThirds method. Called by the stats class which updates * the percentages accordingly. * * @param t0 - first third percentage * @param t1 - second third percentage * @param t2 - third third percentage * */ public void updateThirds(int t0,int t1,int t2){ this.t0 = Integer.toString(t0)+ "%"; this.t1 = Integer.toString(t1) + "%"; this.t2 = Integer.toString(t2)+ "%"; this.repaint(); } /** * paintAll method repaints the panel causing a call to * redraw the pitch and draw the current goal requested by the * viewer * */ private void paintAll(){ f.paintAll(this.getGraphics()); } /** * Method painComponent renders the pitch and prints the relevant * percentages on top * */ public void paintComponent(Graphics g) { super.paintComponent(g); // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); g2d.setFont(font); if(firstHalf){ g2d.drawString(t0, 30, 99); g2d.drawString(t1, 130,99); g2d.drawString(t2, 230,99); }else{ g2d.drawString(t2, 30, 99); g2d.drawString(t1, 130,99); g2d.drawString(t0, 230,99); } } }