使用Graphics2D在纯Java代码中绘制Curly Brace

时间:2016-01-31 07:25:57

标签: java graphics2d

我可以只使用一条曲线在java中绘制花括号。我已经尝试过使用CubicCurve2D,但是我绘制了2条曲线,然后加入它们以获得大括号。

1 个答案:

答案 0 :(得分:1)

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;

public class CurlyBrace extends Frame{

    int preX, preY;
    CubicCurve2D shape;
   public CurlyBrace(){
      super("Java AWT Examples");
      prepareGUI();
   }

   public static void main(String[] args){
      CurlyBrace  awtGraphicsDemo = new CurlyBrace();  
      awtGraphicsDemo.setVisible(true);
   }

   private void prepareGUI(){
      setSize(400,400);
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent windowEvent){
            System.exit(0);
         }        
      }); 
   }    

   @Override
   public void paint(Graphics g) {
       shape = new CubicCurve2D.Float();

      shape.setCurve(150F,100F,200F,90F,130F,200F,190F,220F);
      CubicCurve2D shape2 = new CubicCurve2D.Float();
      shape2.setCurve(190F,220F,140F,230F,190F,350F,150F,340F);

      Graphics2D g2 = (Graphics2D) g; 
      g2.draw (shape);
      g2.draw (shape2);
      Font font = new Font("Serif", Font.PLAIN, 24);
      g2.setFont(font);

   }
}