请问下用Arc2D.Double(double x, double y, double w, double h, double start, double extent, int type) 中的w,h是外围矩形的长和宽嘛?那若已知的是一条圆弧的起始点,起始角度,终止角度,和半径,怎么来求w,h那?
先谢过各位。
------解决方案--------------------
w - 完整椭圆的总宽度,此弧是该椭圆的一部分。
h - 完整椭圆的总高度,此弧是该椭圆的一部分。
如果你知道半径了,那么w,h就是他们的2倍.(-_-!直径)
要是圆弧,相等就是了...
a sample:
- Java code
import java.awt.*;import java.awt.geom.*;import javax.swing.*;public class Test73 { public static void main(String[] args) { // TODO Auto-generated method stub JFrame frame = new DrawFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }}class DrawFrame extends JFrame { public DrawFrame() { // TODO Auto-generated constructor stub setTitle("DrawArc"); setSize(200, 200); add(new DrawPanel()); }}class DrawPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.draw(new Arc2D.Double(40, 50, 100, 50, 0, 60, Arc2D.OPEN)); g2.draw(new Arc2D.Double(40, 50, 100, 50, 120, 60, Arc2D.OPEN)); g2.draw(new Arc2D.Double(40, 50, 100, 50, 240, 60, Arc2D.OPEN)); /*g2.draw(new Arc2D.Double(40, 50, 100, 50, 0, 60, Arc2D.PIE)); g2.draw(new Arc2D.Double(40, 50, 100, 50, 120, 60, Arc2D.PIE)); g2.draw(new Arc2D.Double(40, 50, 100, 50, 240, 60, Arc2D.PIE));*/ }}