今天老师布置了作业,要画一个笑脸
辣么
就发挥一下o(* ̄▽ ̄*)o
画一个杀老师
第一步,找一张杀老师的表情包
第二步,打开IDEA,写一下代码
第三步,运行
代码如下:
import javax.swing.*;
import java.awt.*;
/*
Designed by ziyi
*/
public class Draw1 extends JFrame{
MyPanel myPanel;
public static void main(String[] args){// Instantiate a object
Draw1 frame = new Draw1("Smile");
frame.setVisible(true); //Show the window
}
public Draw1(String title){
super(title);
myPanel= new MyPanel();
this.add(myPanel);//Set title of window////
setDefaultCloseOperation(EXIT_ON_CLOSE); // allow window to close
setSize(600, 600);
}
class MyPanel extends JPanel{
public void paint(Graphics graphics){
graphics.setColor(Color.BLACK);
graphics.fillRect(180,60,140,100);
graphics.fillOval(140,30,220,60);
graphics.setColor(Color.YELLOW);
graphics.fillOval(100,100,300,300);
graphics.setColor(Color.WHITE);
graphics.fillOval(140, 220, 220, 140); // 嘴巴露出微笑
graphics.setColor(Color.YELLOW);
graphics.fillOval(140, 220, 220,100);
graphics.setColor(Color.BLACK);
graphics.fillOval(180,70,140,80);
graphics.fillOval(200,250,10,10);
graphics.fillOval(300,250,10,10);
graphics.drawLine(155,295,155,315);
graphics.drawLine(345,295,345,315);
graphics.drawLine(200,310,200,343);
graphics.drawLine(300,310,300,343);
graphics.drawLine(250,315,250,350);
}
}
}