1
|
import javax.swing.*;
|
2
|
import java.awt.event.*;
|
3
|
import java.awt.*;
|
4
|
|
5
|
public class GraphicsOpsExamples
|
6
|
{
|
7
|
public static void main(String[] args)
|
8
|
{
|
9
|
SwingUtilities.invokeLater(new Runnable()
|
10
|
{
|
11
|
public void run()
|
12
|
{
|
13
|
JFrame frame = new JFrame("Graphics Operations");
|
14
|
frame.setSize(550, 550);
|
15
|
frame.setLocation(150, 150);
|
16
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
17
|
|
18
|
frame.setContentPane(new JComponent()
|
19
|
{
|
20
|
public void paint(Graphics g)
|
21
|
{
|
22
|
Graphics2D g2 = (Graphics2D) g;
|
23
|
|
24
|
g2.drawLine(10, 10, 540, 30);
|
25
|
g2.drawRect(40, 40, 55, 30);
|
26
|
g2.fillRect(150, 40, 55, 30);
|
27
|
g2.drawRoundRect(40, 90, 55, 30, 5, 5);
|
28
|
g2.fillRoundRect(40, 130, 55, 30, 5, 5);
|
29
|
g2.drawRoundRect(110, 90, 55, 30, 8, 8);
|
30
|
g2.fillRoundRect(110, 130, 55, 30, 8, 8);
|
31
|
g2.drawRoundRect(180, 90, 55, 30, 10, 10);
|
32
|
g2.fillRoundRect(180, 130, 55, 30, 10, 10);
|
33
|
g2.drawRoundRect(250, 90, 55, 30, 15, 15);
|
34
|
g2.fillRoundRect(250, 130, 55, 30, 15, 15);
|
35
|
g2.drawRoundRect(320, 90, 55, 30, 20, 20);
|
36
|
g2.fillRoundRect(320, 130, 55, 30, 20, 20);
|
37
|
g2.drawRoundRect(390, 90, 55, 30, 25, 25);
|
38
|
g2.fillRoundRect(390, 130, 55, 30, 25, 25);
|
39
|
g2.drawRoundRect(460, 90, 55, 30, 30, 30);
|
40
|
g2.fillRoundRect(460, 130, 55, 30, 30, 30);
|
41
|
}
|
42
|
});
|
43
|
|
44
|
frame.setVisible(true);
|
45
|
}
|
46
|
});
|
47
|
}
|
48
|
}
|