/** * Put User Payoff history into a readable double 2D array for JFreeChart * * @return A 2D double array of coordinates */ private XYSeries getUserPayoffData() { XYSeries xySeries = new XYSeries("User: "******"'s Payoff History (Over " + userInfo.getPayoffHistory().size() + " Steps)"); // Set the points of the data set for (int i = 0; i < userInfo.getPayoffHistory().size(); i++) { xySeries.add(i, userInfo.getPayoffHistory().get(i)); } return xySeries; }
/** * 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); }