Browse Source

statisticgraph anfang

Kevin Trometer 7 years ago
parent
commit
3b502b4110

BIN
bin/ui/controller/Control.class


BIN
build/resources/main/Images/Thumbs.db


BIN
build/resources/test/Images/Thumbs.db


+ 93 - 0
src/ui/view/StatisticGraph.java

@@ -0,0 +1,93 @@
+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);
+	}
+
+}