2012-11-17 34 views
1

我一直使用此代碼畫弧在Java弧:企圖拉攏使用Java

g.fillArc(50, 50, 100, 100, 0, 180) 

其中g是一個圖形對象。

這將產生下面的藍色對象:

result

什麼,我實際上是試圖做的是生產的東西,看起來像這樣:

striving for

先感謝您的任何幫幫我!

回答

3

改爲嘗試g.fillArc(50, 50, 100, 100, 180, 180)

基本上,第一個角度是從哪裏開始,第二個角度是它應該通過的度數(從開始)。

所以,如果你只是想5度的餡餅滑,你會使用類似g.fillArc(50, 50, 100, 100, 0, 5)

看一看Graphics#fillArcGraphics2D更多信息

工作實例

enter image description here

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);   
     } 

    } 

} 
+1

即使'g.fillArc(50,50,100, 100,0,-180)'應該沒問題。 – Jack

+0

@Jack Yep,你是對的,忘了提及那個;) – MadProgrammer

+0

嗯,那裏的第一個排隊似乎沒有結果,因爲它不會產生任何可見的對象。 –