-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawingComponent.java
More file actions
61 lines (50 loc) · 1.64 KB
/
DrawingComponent.java
File metadata and controls
61 lines (50 loc) · 1.64 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class DrawingComponent extends JComponent
{
private final int STROKE_WIDTH = 5;
private int xLeft;
private int yTop;
public DrawingComponent()
{
xLeft = 30;
yTop = 30;
}
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(STROKE_WIDTH));
drawPlayStation(g, xLeft, yTop, 400);
}
void drawPlayStation(Graphics g, int xLeft, int yTop, int width)
{
g.setColor(Color.BLUE);
g.drawLine(xLeft, yTop, xLeft + width/4, yTop + width/4);
g.drawLine(xLeft, yTop + width/4, xLeft+ width/4, yTop);
g.setColor(Color.RED);
g.drawOval(xLeft + width/4, yTop, width/4, width/4);
g.setColor(Color.MAGENTA);
g.drawRect(xLeft + width/2, yTop, width/4, width/4);
g.setColor(Color.GREEN);
g.drawLine(xLeft + (width/4 * 3), yTop + (width/4), xLeft + width, yTop + (width/4));
g.drawLine(xLeft + (width/4 * 3), yTop + (width/4), xLeft + (width/8 * 7), yTop);
g.drawLine(xLeft + (width/8 * 7), yTop, xLeft + width, yTop + (width/4));
// g.setColor(Color.BLACK);
// g.drawString("x, circle, square, triangle", 50, width/2);
}
public void moveDrawingTo(int x, int y)
{
xLeft = x;
yTop = y;
repaint();
}
public void moveDrawingBy(int dx, int dy)
{
xLeft = xLeft + dx;
yTop = yTop + dy;
repaint();
}
}