drawOvalpublic abstract void drawOval(int x,
int y,
int width,
int height)
- 繪制橢圓的邊框。得到一個(gè)圓或橢圓,它剛好能放入由
x 、y 、width 和 height 參數(shù)指定的矩形(指的是外接矩形)中。
橢圓覆蓋區(qū)域的寬度為 width + 1 像素,高度為 height + 1 像素。
-
- 參數(shù):
x - 要繪制橢圓的左上角的 x 坐標(biāo)。
y - 要繪制橢圓的左上角的 y 坐標(biāo)。
width - 要繪制橢圓的寬度。
height - 要繪制橢圓的高度。
舉例如下:
1、編寫applet程序1,在屏幕上畫一組同心圓,相鄰兩圓的直徑大小相差10(pixel);
import java.applet.*; import java.awt.Color; import java.awt.Graphics; import java.util.Random;
public class AppletCircle extends Applet { public void init() { this.setSize(400, 400); }
public void paint(Graphics g) { Color color ; for (int i=0; i<20; i++){ color = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)); g.setColor(color); g.drawOval(20+5*i, 30+5*i, 300-10*i, 300-10*i); } }
public static void main(String[] args){ new AppletCircle(); } }
|