-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawShapes.java
More file actions
77 lines (70 loc) · 2.08 KB
/
DrawShapes.java
File metadata and controls
77 lines (70 loc) · 2.08 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Name: Rishi Saravanan
//Date: 2/8/21
//Program Name: DrawShapes
//Program Goal: Draw shapes and trace out your name using GUI
import java.awt.*;
import javax.swing.*;
public class DrawShapes extends JFrame {
public static void main(String[] args) {
DrawShapes d1 = new DrawShapes();
}
public DrawShapes() {
super("Draw Shapes");
setSize(600, 600);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLocation(200, 100);
setResizable(true);
Panel pan = new Panel();
setContentPane(pan);
setVisible(true);
}
}
class Panel extends JPanel {
public Panel() {
setBackground(Color.YELLOW);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < 600; i += 20) {
g.setColor(Color.BLACK);
g.drawLine(i, 0, i, 600);
g.drawLine(0, i, 600, i);
}
g.drawRect(220, 60, 140, 80);
g.setColor(new Color(165, 42, 42));
g.fillRect(220, 60, 140, 80);
g.setColor(new Color(125, 32, 32));
((Graphics2D) g).setStroke(new BasicStroke(5));
g.drawRect(220, 60, 140, 80);
g.setColor(new Color(165, 42, 42));
g.drawOval(100, 60, 60, 60);
g.setColor(new Color(165, 42, 42));
g.fillOval(100, 60, 60, 60);
g.setColor(new Color(125, 32, 32));
((Graphics2D) g).setStroke(new BasicStroke(5));
g.drawOval(100, 60, 60, 60);
g.setColor(new Color(165, 42, 42));
((Graphics2D) g).setStroke(new BasicStroke(4));
g.drawLine(120, 180, 120, 280);
g.drawLine(120, 180, 200, 180);
g.drawLine(200, 180, 200, 240);
g.drawLine(200, 240, 120, 240);
g.drawLine(120, 240, 200, 280);
g.drawLine(220, 280, 300, 280);
g.drawLine(260, 280, 260, 180);
g.drawLine(220, 180, 300, 180);
g.drawLine(400, 180, 320, 180);
g.drawLine(320,180, 320, 230);
g.drawLine(320, 230, 400, 230);
g.drawLine(400,230, 400 ,280);
g.drawLine(400, 280, 320, 280);
g.drawOval(120, 320, 140, 100);
g.fillOval(120, 320, 140, 100);
g.setColor(Color.BLACK);
Font sansSerif = new Font("SansSerif" , Font.PLAIN, 20);
g.setFont(sansSerif);
g.drawString("DrawShapes.java", 280, 40);
g.setColor(new Color(165, 42, 42));
g.drawArc(320 ,320 ,120, 80 ,270, 180);
}
}