Drawing a nice circle in Java

后端 未结 5 882
生来不讨喜
生来不讨喜 2021-02-09 18:06

I\'m using Java Graphics and I keep getting \"ugly\" circles.

Here\'s what my Java program makes \"enter

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-09 18:47

    You can enable anti-aliasing:

    Graphics2D g2 = (Graphics2D) g;
    Map hints = new HashMap();
    hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
    g2.setRenderingHints(hints);
    

    I also suggest you draw to the Graphics object you get from the paintComponent method rather than creating an intermediate BufferedImage.

提交回复
热议问题