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) {
// TODO 自动生成的方法存根
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);
}
}
【Java】 GUI 在黑色背景画上随机色彩的圆圈
最新推荐文章于 2021-05-20 23:52:47 发布