-
Notifications
You must be signed in to change notification settings - Fork 1
/
GraphicsDemo3.java
46 lines (39 loc) · 1.44 KB
/
GraphicsDemo3.java
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.*;
import java.swing.JFrame;
public class GraphicsDemo3 extends Canvas {
public void paint(Graphics g) {
//lines
g.setColor(Color.green);
g.drawLine(10,100,400,100);
g.setColor(Color.blue);
g.drawLine(50,150,100,180);
g.setColor(Color.magenta);
g.drawLine(100,350,300,230);
g.setColor(Color.black);
// fonts
g.drawString("Graphics are pretty neat.", 500, 100);
g.setFont(new Font("Consolas", Font.PLAIN, 36)); // 36-pt plain
g.drawString("Yes, they are.", 400, 200);
g.setColor(Color.white);
g.setFont(new Font("Calibri", Font.BOLD+Font.ITALIC, 60)); // 60 pt italic bold
g.drawString("Leander Lions", 300, 350);
g.setColor(Color.blue);
g.setFont(Font.decode("Calibri-BOLDITALIC-60")); // a different way to specify a font
g.drawString("Leander Lions", 290, 360);
g.setColor(Color.black);
g.setFont(new Font(null)); // restore default font
int x = 400, y = 490;
g.drawRect(x,y,150,20);
g.drawString("Where is the starting point?", x, y);
g.setColor(Color.red);
g.drawLine(x, y, x, y); // drawing a line from a point to itself makes a 1 px by 1-px dot
}
public static void main(String[] args) {
JFrame win = new JFrame("GraphicsDemo3: Fonts and Lines");
win.setSize(800,600);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicsDemo3 canvas = new GraphicsDemo3();
win.add(canvas);
win.setVisible(true);
}
}