本节内容视频链接:10、画笔paint_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1DJ411B75F?p=10&vd_source=b5775c3a4ea16a5306db9c7c1c1486b5
package com.yundait.lesson03;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestPaint {
public static void main(String[] args) {
myPaint myPaint = new myPaint();
myPaint.loadFrame();
myPaint.closeWindows();
}
}
class myPaint extends Frame {
//加载窗口
public void loadFrame(){
setBounds(300,300,600,500);
setVisible(true);
}
//窗口画笔工具
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
g.drawOval(100,100,100,100);
g.fillOval(300,300,100,100);
g.setColor(Color.green);
g.fillRect(200,200, 100,200);
}
//监听窗口关闭
public void closeWindows(){
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}