⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moonapplet.java

📁 这是一个用Java编写的能够实现画月亮的小程序
💻 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 + -