位置:首页 > Java技术 > AWT > AWT Ellipse2D类

AWT Ellipse2D类

Ellipse2D的类声明所定义的框架矩形椭圆。

类的声明

以下是声明java.awt.geom.Ellipse2D类:

public abstract class Ellipse2D
   extends RectangularShape

类的构造函数

S.N. 构造函数与说明
1 protected Ellipse2D() 
This is an abstract class that cannot be instantiated directly.

类方法

S.N. 方法和说明
1 boolean contains(double x, double y) 
Tests if the specified coordinates are inside the boundary of the Shape.
2 boolean contains(double x, double y, double w, double h) 
Tests if the interior of the Shape entirely contains the specified rectangular area.
3 boolean equals(Object obj) 
Determines whether or not the specified Object is equal to this Ellipse2D.
4 PathIterator getPathIterator(AffineTransform at) 
Returns an iteration object that defines the boundary of this Ellipse2D.
5 int hashCode() 
Returns the hashcode for this Ellipse2D.
6 boolean intersects(double x, double y, double w, double h) 
Tests if the interior of the Shape intersects the interior of a specified rectangular area.

继承的方法

这个类继承的方法从以下类:

  • java.lang.Object

Ellipse2D 实例

选择使用任何编辑器创建以下java程序 D:/ > AWT > com > yiibai > gui >

AWTGraphicsDemo.java
package com.yiibai.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 comyiibaiguiAWTGraphicsDemo.java

如果没有错误出现,这意味着编译成功。使用下面的命令来运行程序。

D:AWT>java com.yiibai.gui.AWTGraphicsDemo

验证下面的输出

AWT Ellipse2D