[英]Trying to draw an arc using Java
我一直在尝试使用以下代码在java中绘制弧:
g.fillArc(50, 50, 100, 100, 0, 180)
其中g是图形对象。
产生下面的蓝色物体:
我实际上要做的是产生如下所示的东西:
在此先感谢您的帮助!
请尝试g.fillArc(50, 50, 100, 100, 180, 180)
。
基本上,第一个角度是从哪里开始,第二个角度是它应该通过的度数(从一开始)。
所以,如果你只想要一个5度的馅饼,你会使用类似g.fillArc(50, 50, 100, 100, 0, 5)
有关更多信息,请查看Graphics#fillArc
和Graphics2D
工作实例
public class PaintTest03 {
public static void main(String[] args) {
new PaintTest03();
}
public PaintTest03() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (UnsupportedLookAndFeelException ex) {
}
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new PaintPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class PaintPane extends JPanel {
@Override
public Dimension getPreferredSize() {
return new Dimension(100, 100);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.fillArc(0, 0, 100, 100, 180, 180);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.