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
| public class DemoArc extends JPanel {
private final static Point P1 = new Point(300,150);
private final static Point P1B = new Point(350,250);
private final static Point P2 = new Point(150,100);
private final static Point P2B = new Point(50,150);
private final static CubicCurve2D CURVE = new CubicCurve2D.Double(P1.x, P1.y, getCtrl(P1.x,P1B.x), getCtrl(P1.y,P1B.y), getCtrl(P2.x,P2B.x), getCtrl(P2.y,P2B.y), P2.x, P2.y);
public DemoArc() {
setBackground(Color.BLACK);
}
private static double getCtrl(int v1, int v2) {
return v1 - (v2-v1);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.YELLOW);
g.drawLine(P1.x, P1.y, P1B.x, P1B.y);
g.setColor(Color.RED);
g.drawLine(P2.x, P2.y, P2B.x, P2B.y);
g.setColor(Color.WHITE);
((Graphics2D)g).draw(CURVE);
}
public static void main(String[] args) {
JFrame frame=new JFrame("t");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new DemoArc());
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
} |
Partager