ランダムに生成されたx座標で固定線長を使用して、降雨をシミュレートしようとしています。ランダムなx座標を機能させましたが、ウィンドウに再描画した後も、線の立ち下がり速度を変えたいと思います。私はjavaxスイングタイマーとjavaRandomを使用して整数を生成し、インデックスとして「速度」配列に渡します。ただし、速度は変わりません。それは同じままで、速すぎます。
public class rain extends JPanel implements ActionListener {
int i = 0;
int[] speed = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50};
double[] x = {10, 202, 330, 140, 250, 160, 470, 180, 290, 510};
double y1 = 10, y2 = 20;
double down = 1;
Random random = new Random();
//Timer t = new Timer(speed[i], this);
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D l = (Graphics2D) g;
Line2D line = new Line2D.Double(x[i], y1, x[i], y2);
l.setColor(Color.blue);
l.draw(line);
Timer t = new Timer(speed[i], this);
t.start();
}
public void actionPerformed(ActionEvent e) {
if (y2 < 380) {
y1 += down;
y2 += down;
}else{
y1 = 10;
y2 = 20;
i = random.nextInt(10);
}
repaint();
}