/** * Draws the chart using graphics * * @param g Graphics to Draw to */ public void drawChart(Graphics g) { // Update all chart data refreshChartData(); // Paint the chart if (chart != null && g != null) chart.draw( (Graphics2D) g, (Rectangle2D) new Rectangle2D.Double( 0, 0, g.getClipBounds().getWidth(), g.getClipBounds().getHeight())); }
/** * Create a GUI that shows a graph for the specified user's payoff history * * @param user The user to show the Payoff history for */ public GraphGUI(User user) { super( user.getUserName() + "'s Payoff History (Over " + user.getPayoffHistory().size() + " Steps)"); this.userInfo = user; this.pack(); // Set size this.setMinimumSize(new Dimension(500, 500)); // Center the graph this.setLocationRelativeTo(null); // Create a series collection xySeriesCollection = new XYSeriesCollection(); // Create (refresh) chart data refreshChartData(); // Create an XY Line Chart chart = ChartFactory.createXYLineChart( "User Payoff Over Time", "Steps (Simulation Iterations)", "User Payoff", xySeriesCollection); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getPlot().setOutlinePaint(Color.BLACK); // Draw the Initial Chart chart.draw( (Graphics2D) this.getGraphics(), (Rectangle2D) new Rectangle2D.Double(0, 0, this.getWidth(), this.getHeight())); // Set the content pane to a graphics panel for drawing the graph this.setContentPane(new GraphPanel(this)); // Show the frame this.setVisible(true); // Subscribe to the user's UserPayoff events user.addPayoffListener(this); }