aboutsummaryrefslogtreecommitdiff
path: root/src/main/block.java
blob: cb04132e39d040864b28b70cfe8aa471cf4c8d25 (plain) (blame)
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
78
79
80
81
82
83
84
85
package main;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Path2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

//

public class block {

    public static void main(String[] args) {
        new block();
    }

    public block() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                /*try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }
                */

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new TestPane());
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                
            }
        });
    }

    public class TestPane extends JPanel {

        private RightEnd rightEnd;

        public TestPane() {
            rightEnd = new RightEnd(100, 100, 40);
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(100, 100);
        }

        
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int x = (getWidth() - 100) / 2;
            int y = (getHeight()- 100) / 2;
            Graphics2D g2d = (Graphics2D) g.create();
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.translate(x, y);
            g2d.fill(rightEnd);
            g2d.dispose();
        }
        

    }

    public class RightEnd extends Path2D.Float {

        public RightEnd(float width, float height, float radius) {
            moveTo(0, 0);
            lineTo(width - radius, 0);
            curveTo(width, 0, width, 0, width, radius);
            lineTo(width, height - radius);
            curveTo(width, height, width, height, width - radius, height);
            lineTo(0, height);
            closePath();
        }
    }
}