- AWT 教程
- AWT - 主頁
- AWT - 概覽
- AWT - 環境
- AWT - 控制元件
- AWT - 事件處理
- AWT - 事件類
- AWT - 事件偵聽器
- AWT - 事件介面卡
- AWT - 佈局
- AWT - 容器
- AWT - 選單
- AWT - 圖形
- AWT 有用資源
- AWT - 快速指南
- AWT - 有用資源
- AWT - 討論
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.javapackage 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_graphics.htm
廣告