AWT Ellipse2D 類



導言

Ellipse2D 類聲明瞭一個由邊框長方形定義的橢圓。

類宣告

以下是 java.awt.geom.Ellipse2D 類的宣告

public abstract class Ellipse2D
   extends RectangularShape

類建構函式

序號建構函式和說明
1

protected Ellipse2D()

這是一個抽象類,不能直接例項化。

類方法

序號方法和說明
1

boolean contains(double x, double y)

測試指定座標是否在 Shape 的邊界內。

2

boolean contains(double x, double y, double w, double h)

測試 Shape 的內部是否完全包含指定的矩形區域。

3

boolean equals(Object obj)

確定指定的 Object 是否與此 Ellipse2D 相等。

4

PathIterator getPathIterator(AffineTransform at)

返回定義此 Ellipse2D 邊界的迭代物件。

5

int hashCode()

返回此 Ellipse2D 的雜湊碼。

6

boolean intersects(double x, double y, double w, double h)

測試 Shape 的內部是否與指定矩形區域的內部相交。

繼承的方法

此類繼承自以下類的方法

  • java.lang.Object

Ellipse2D 示例

在您選擇的任何編輯器中(如 D:/ > AWT > com > tutorialspoint > gui >)中建立以下 java 程式

AWTGraphicsDemo.java
package com.tutorialspoint.gui;

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

public class AWTGraphicsDemo extends Frame {
       
   public AWTGraphicsDemo(){
      super("Java AWT Examples");
      prepareGUI();
   }

   public static void main(String[] args){
      AWTGraphicsDemo  awtGraphicsDemo = new AWTGraphicsDemo();  
      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) {
      Ellipse2D shape = new Ellipse2D.Float();
      shape.setFrame(100, 150, 200,100);
      Graphics2D g2 = (Graphics2D) g; 
      g2.draw (shape);
      Font font = new Font("Serif", Font.PLAIN, 24);
      g2.setFont(font);
      g.drawString("Welcome to TutorialsPoint", 50, 70);
      g2.drawString("Ellipse2D.Oval", 100, 120); 
   }
}

使用命令提示符編譯程式。轉到 D:/ > AWT,然後鍵入以下命令。

D:\AWT>javac com\tutorialspoint\gui\AWTGraphicsDemo.java

如果沒有出現錯誤,則表示編譯成功。使用以下命令執行程式。

D:\AWT>java com.tutorialspoint.gui.AWTGraphicsDemo

驗證以下輸出

AWT Ellipse2D
awt_graphics.htm
廣告
© . All rights reserved.