- 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
广告