123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package ui.view;
- import java.awt.BasicStroke;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.RenderingHints;
- import java.awt.geom.GeneralPath;
- import java.util.LinkedList;
- import javax.swing.JPanel;
- import classes.HolonObject;
- import ui.controller.Control;
- import ui.model.Model;
- public class StatisticGraph extends JPanel {
- public StatisticGraph() {
- }
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- // model and controller
- private Model model;
- private Control controller;
- // Graphics2D
- private Graphics2D g2;
- GeneralPath path = new GeneralPath();
- // Data
- private LinkedList<HolonObject> objects = new LinkedList<>();
- /**
- * Constructor.
- *
- * @param model
- * the Model
- * @param control
- * the Controller
- */
- public StatisticGraph(final Model model, Control control) {
- this.controller = control;
- this.model = model;
- this.setBackground(Color.WHITE);
- }
- /**
- * Paints all Components on the Canvas.
- *
- * @param g
- * Graphics
- *
- */
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- path.reset();
-
- g2 = (Graphics2D) g;
- RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHints(rh);
- g2.setStroke(new BasicStroke(0));
- g2.setColor(Color.BLACK);
- for (int i = 0; i <= this.getWidth(); i += 10) {
- g2.drawLine(i, 0, i, this.getHeight());
- }
- for (int i = 0; i <= this.getHeight(); i += 5) {
- g2.drawLine(0, i, this.getWidth(), i);
- }
- g2.setColor(Color.BLUE);
- g2.setStroke(new BasicStroke(2));
-
- path.moveTo(0,this.getHeight());
- for (int i = 0; i <= 49; i++) {
- double coordY = Math.random()*this.getHeight();
- controller.addTextToConsole(""+i);
- path.lineTo(i*this.getWidth()/49, coordY);
- path.moveTo(i*this.getWidth()/49, coordY);
- }
-
- g2.draw(path);
- }
- }
|