📄 rainpanel.java
字号:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
/*
* Created on Jul 3, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author Fabian Jones AD Summer Intern 2003
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class RainPanel extends JPanel{
private static int DEFAULT_WIDTH = 500;
private static int DEFAULT_HEIGHT = 500;
private static int NUM_DROPS = 500;
private RainDrop[] rainDrops = new RainDrop[500];
public RainPanel(){
createRainDrops();
createPanel();
}
private void createRainDrops(){
for(int i = 0; i < rainDrops.length; ++i){
createRainDrop(i);
}
}
private void createRainDrop(int index){
int randomX = (int) (Math.random()*500);
int randomY = (int) (Math.random()*300);
int randomV = (int) (Math.random()*10);
rainDrops[index] = new RainDrop(randomX, randomY, randomV);
}
private void createPanel(){
this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
this.setBackground(Color.WHITE);
}
public void paint(Graphics g){
for(int i = 0; i < rainDrops.length; ++i){
rainDrops[i].paint(g);
if(rainDrops[i].x > DEFAULT_WIDTH || rainDrops[i].y > DEFAULT_HEIGHT){
createRainDrop(i);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -