summaryrefslogtreecommitdiff
path: root/labs/lab02_simpleRGB/RGBComponent.java
blob: 8a1576efbbb6a91a0d68238e5f12c7cf2dc85fd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;

import javax.swing.JComponent;

@SuppressWarnings("serial")
public class RGBComponent extends JComponent
{
	private SimpleRGB image;
	private int width;
	private int height;
	
	public RGBComponent(SimpleRGB anImage)
	{
		image = anImage;
		width = image.getWidth();
		height = image.getHeight();
	}
	
	public void paintComponent(Graphics g)
	{
		Graphics2D g2 = (Graphics2D) g;
		
		Line2D.Double line = new Line2D.Double(0,0,0,0);
		
		// Draw the Board

		for(int w = 0; w < width; w++)
		{
			for(int h = 0; h < height; h++)
			{
				g2.setColor(new Color(image.getRed(w, h), image.getGreen(w, h), image.getBlue(w, h)));
				line.setLine(w, h, w, h);
				g2.draw(line);
			}
		}
	}
	
	public void setImage(SimpleRGB anImage)
	{
		image = anImage;
		repaint();
	}
}