import javax.swing.*;
import java.awt.*;
public class SystemUI{
public SystemUI() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(400, 300, 500, 300);
frame.setVisible(true);
DrawPanel dpanel = new DrawPanel();
frame.add(dpanel);
}
public static void main(String[] args) {
new SystemUI();
}
}
class DrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
g.fillRect(0, 0, getWidth(), getHeight());
int red = (int)(Math.random()*255);
int green = (int)(Math.random()*255);
int blue = (int)(Math.random()*255);
Color randomColor = new Color(red,green,blue);
g.setColor(randomColor);
g.fillOval(70, 70, 100, 100);
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200423225007133.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyOTAwMjg2,size_16,color_FFFFFF,t_70)