Project

General

Profile

GraphicsOpsExamples.java

Greg Shah, 07/23/2015 06:09 PM

Download (2.48 KB)

 
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(600, 600);
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, 590, 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
                  g2.setColor(Color.GREEN);
42
                  g2.draw3DRect(40, 175, 75, 30, true);
43
                  g2.draw3DRect(130, 175, 150, 60, true);
44
                  g2.fill3DRect(295, 175, 75, 30, true);
45
                  g2.fill3DRect(395, 175, 150, 60, true);
46
                  g2.draw3DRect(40, 250, 75, 30, false);
47
                  g2.draw3DRect(130, 250, 150, 60, false);
48
                  g2.fill3DRect(295, 250, 75, 30, false);
49
                  g2.fill3DRect(395, 250, 150, 60, false);
50
                  g2.setColor(Color.BLACK);
51
                  g2.draw3DRect(40, 325, 75, 30, false);
52
                  g2.draw3DRect(130, 325, 150, 60, false);
53
                  g2.fill3DRect(295, 325, 75, 30, false);
54
                  g2.fill3DRect(395, 325, 150, 60, false);
55
               }
56
            });
57
            
58
            frame.setVisible(true);
59
         }
60
      });
61
   }
62
}