gedas 0 Junior Poster

hey,

can someone explain to me exactly how this code works because i dont really understand the logic of it.

public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Dimension d = getSize();
		checkOffScreenImage();
		Graphics offG = mImage.getGraphics();
		offG.setColor(backgroundColor);
		offG.fillRect(0, 0, d.width, d.height);
		Graphics2D g2 = (Graphics2D) mImage.getGraphics();
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);

		// draw medium line
		int yLine = getHeight() - 25;

		g2.setPaint(lineColor);
		g2.drawLine(0, yLine, getWidth(), yLine);
		RawAcceleration[] valuesArray = values.toArray(new RawAcceleration[0]);

		double unit = yLine / 255.0;
		int previousX = 0;
		int previousY = 0;
		int previousZ = 0;
		// draw curves
		for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
			RawAcceleration acceleration = valuesArray[i];
			// draw X
			g2.setPaint(xColor);
			int yDelta = (int) Math.round(unit * acceleration.getX());
                     
			int y = -1 * yDelta + yLine;
			g2.drawLine(i - 1, previousX, i, y);
			g2.setTransform(new AffineTransform());
			previousX = y;
			// draw Y
			g2.setPaint(yColor);
			yDelta = (int) Math.round(unit * acceleration.getY());
			y = -1 * yDelta + yLine;
			g2.drawLine(i - 1, previousY, i, y);
			g2.setTransform(new AffineTransform());
			previousY = y;
			// draw Z
			g2.setPaint(zColor);
			yDelta = (int) Math.round(unit * acceleration.getZ());
			y = -1 * yDelta + yLine;
			g2.drawLine(i - 1, previousZ, i, y);
			g2.setTransform(new AffineTransform());
			previousZ = y;
		}

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.