📄 moonapplet.java
字号:
//【例8.1】 在Applet中画月亮。
import java.awt.*;
import java.applet.Applet;
public class MoonApplet extends Applet
{
public void paint(Graphics g) //在Applet上绘图
{
g.setColor(Color.red);
g.drawString("The Moon",100,20);
int x=0,y=0; //圆外切矩形左上角坐标
x = this.getWidth() /4;
y = this.getHeight() /4;
int diameter = Math.min(this.getWidth()/2, this.getHeight()/2); //圆的直径
g.setColor(Color.yellow);
g.fillOval(x,y,diameter,diameter); //画圆
g.setColor(this.getBackground()); //设置为背景色
g.fillOval(x-20,y-20,diameter,diameter); //画圆
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -