Я пытаюсь написать дождь на java, но пока никак не могу заставить дождинку двигаться:
package com.company;
public class Main {
public static void main(String[] args) {
MyWindow myWindow = new MyWindow();
}
}
package com.company;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class MyWindow extends JFrame {
public MyWindow() {
setTitle("My Window");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setBounds(300, 300, 500, 400);
setLayout(new BorderLayout());
RainField RF = new RainField();
add(RF, BorderLayout.CENTER);
setResizable(true);
setVisible(true);
}
}
package com.company;
import javax.swing.*;
import java.awt.*;
public class RainField extends JPanel {
public int i = 0;
protected float x = getWidth() / 2, y = 0, yspeed = 1;
public RainField() {
for (i = 0; i < 1000; i++) {
y += 10;
// repaint();
}
}
protected void paintComponent(Graphics g) {
setBackground(Color.orange);
int x = getWidth() / 2;
int y = 99;
g.setColor(Color.BLUE);
g.drawLine(x, y, x, y + 10);
}
}