课堂派图形作业

  • Post author:
  • Post category:其他


第一题

package com.company;

import javax.swing.*;
import java.awt.*;

public class Main {

    public static void main(String[] args) {
        myJframe jf=new myJframe();
        jf.setTitle("绘制几何图像");
	// write your code here
    }
}
class myJframe extends JFrame{
    public myJframe(){
        setSize(500,300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    public void paint(Graphics g){
        g.drawOval(20,40,100,100);
        g.fillRoundRect(130,40,100,100,100,100);
        g.drawRect(240,40,100,100);
        g.fillRect(350,40,100,100);
        g.drawOval(20,150,100,100);
        g.drawArc(130,150,100,100,75,-210);
        g.fillArc(240,150,100,100,75,-210);
        Polygon polygon1=new Polygon();
        polygon1.addPoint(350,150);
        polygon1.addPoint(450,150);
        polygon1.addPoint(400,200);
        polygon1.addPoint(350,250);
        polygon1.addPoint(450,250);
        g.drawPolygon(polygon1);

    }
}

在这里插入图片描述

第二题

package com.company;

import javax.swing.*;
import java.awt.*;

public class Main {

    public static void main(String[] args) {
        myJframe jf=new myJframe();
        jf.setTitle("my first");
    }
}
class myJframe extends JFrame {
    JPanel jp=new JPanel();
    public myJframe() {
        setSize(500, 300);
        setLocationRelativeTo(null);
        add(jp);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public void paint(Graphics g) {
        g.setColor(Color.BLUE);
        g.fillArc(200,100,100,100,0,60);
        g.fillArc(200,100,100,100,90,60);
        g.fillArc(200,100,100,100,180,60);
        g.fillArc(200,100,100,100,-20,-60);
    }
}

在这里插入图片描述

第三题

package com.company;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class Main {

    public static void main(String[] args) {
        myJframe jf=new myJframe();
        jf.setTitle("my first");
    }

}
class myJframe extends JFrame {
    public myJframe() {
        setSize(500, 300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public void paint(Graphics g) {
        Random rand = new Random();
        g.drawRect(150,120,150,60);
        g.setFont(new Font("Tahoma", Font.BOLD, 50));
        g.setColor(Color.BLUE);
        g.drawString("50vx",165,165);
        g.setColor(Color.BLACK);
        for(int i=0; i<50; i++) {
            int x=(int)(Math.random()*150 + 150);
            int y=(int)(Math.random()*60+ 120);
        g.drawLine(x,y,x,y);
        }

    }}

在这里插入图片描述

第四题

package com.company;

import javax.swing.*;
import java.awt.*;

public class Main {

    public static void main(String[] args) {
        myJframe jf=new myJframe();
    }
	// write your code here
    }
class myJframe extends JFrame {
    public myJframe() {
        setSize(500, 400);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);

    }
    public void paint(Graphics g) {
        g.drawRoundRect(200,40,100,100, 100, 100);
        g.drawRect(205,140,85,120);
        g.drawLine(150,250,205,140);
        g.drawLine(345,250,290,140);
        g.drawLine(205,260,150,370);
        g.drawLine(290,260,345,370);
        //g.setFont(new Font("微软雅黑", Font.BOLD, 20));
        //g.drawString("giao~",230,200);
    }
}

在这里插入图片描述



版权声明:本文为qq_52746199原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。