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

📄 dao.java

📁 java第89章的实验,对学习java很有帮助的.
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;

public class Dao extends JFrame{

    /** Creates a new instance of SimpleFrame */
    public Dao() {
        setSize(width,height);//设置框架大小
        setTitle("道");//设置框架标题
        //将框架显示在屏幕正中
        Toolkit kit= Toolkit.getDefaultToolkit();
        Dimension screenSize=kit.getScreenSize();
        int x=(screenSize.width-width)/2;
        int y=(screenSize.height-height)/2;
        setLocation(x,y);//设置框架位置
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String args[]) {
        Dao frame=new Dao();
        DrawPanel drawPanel=new DrawPanel( );
        //把其它组件添加到面板中;
        frame.setContentPane(drawPanel);
        frame.setVisible(true);
    }
    int width=400;
    int height=200;
}

class DrawPanel extends JPanel{
    public  DrawPanel(){
        setBackground(Color.lightGray);
    }
    //在面板中绘制图形;

    public void paintComponent(Graphics g)  {
        super.paintComponent(g);
        g.setColor(Color.BLACK);
        g.fillArc(x,y, d, d,0,180);
        g.setColor(Color.WHITE);
        g.fillArc(x,y, d, d,180,180);
        g.setColor(Color.BLACK);
        g.fillArc(x+d/2, y+d/4, d/2, d/2,180,180);
        g.setColor(Color.WHITE);
        g.fillArc(x, y+d/4, d/2, d/2,0,180);
        g.fillOval(x+d*3/4-5, y+d/2-5, 10,10);
        g.setColor(Color.BLACK);
        g.fillOval(x+d/4-5, y+d/2-5, 10,10);
     }
   /*
    *绘图分解演示
     public void paintComponent(Graphics g)  {
        super.paintComponent(g);
        g.setColor(Color.BLACK);
        g.fillArc(x,y, d, d,0,180);
        g.setColor(Color.WHITE);
        g.fillArc(x,y, d, d,180,180);
        x=x+d;
        g.setColor(Color.BLACK);
        g.fillArc(x+d/2, y+d/4, d/2, d/2,180,180);
        x=x+d;
        g.setColor(Color.WHITE);
        g.fillArc(x, y+d/4, d/2, d/2,0,180);
        x=x+60;
        g.fillOval(x+d*3/4-5, y+d/2-5, 10,10);
        x=x+20;
        g.setColor(Color.BLACK);
        g.fillOval(x+d/4-5, y+d/2-5, 10,10);
     }
    * */
    int x=10;
    int y=40;
    int d=100;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -