📄 paintframe.java
字号:
package 彩蛋;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class PaintFrame extends JFrame {
private int eor , vor;
JPanel panel;
int num= 6;
public PaintFrame() {
this.setSize(500, 335);
this.setTitle("彩蛋程序");
this.setVisible(true);
this.setLocation(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyPanel p = new MyPanel();
this.getContentPane().add(p);
}
public class MyPanel extends JPanel {
public MyPanel() {
this.setSize(500, 300);
eor = this.getWidth()/num;
vor = this.getHeight()/num;
SleepThread s = new SleepThread();
Thread t = new Thread(s);
t.start();
}
public void paintComponent(Graphics g) {
for(int i = 0;i<num;i++) {
for(int j =0;j<num;j++) {
Random r = new Random();
Color c = new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255));
g.setColor(c);
g.fillOval(i*eor, j*vor, eor, vor);
}
}
}
}
public class SleepThread implements Runnable {
public void run() {
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
repaint();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -