Ohne weitere Umschweife werde ich einfach den Java-Code für Sie posten.
import java.awt.Color; import java.awt.Image.BufferedImage; import javax.swing.JPanel; final int MAX = ; (~)Die Anzahl der Meteore final int SLEEP = ; // Die Geschwindigkeit des Meteoritenfluges (je größer der Wert, desto langsamer die Geschwindigkeit) final int COLORLV = ; (~) Farbskala (kann die Halo-Größe ändern) final String COLOR = null; // ("#"~"#ffffff") Halo-Farbe (wenn nicht ausgefüllt oder null, ist es die Standardfarbe) final int SIZE = ; // (~) Meteor size private MyPanel() { panel = new MyPanel(, ); Erstellen Sie ein Formular this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new MeteorFly(); AppletWidth, AppletHeight; BufferedImage OffScreen; drawOffScreen; public MyPanel() { setBackground(Color.black); //Formularinitialisierung AppletWidth = ; ] = new Meteor(); OffScreen = new BufferedImage(AppletWidth, AppletHeight, BufferedImage.TYPE_INT_BGR); drawOffScreen = OffScreen.getGraphics(); pThread = new Thread(this); pThread.start(); } @Override public void paintComponent(Graphics g) { // TODO Automatisch generierter Methoden-Stub super.paintComponents( g); g.drawImage(OffScreen, , , this); } @Override final public void run() { while (true) { // drawOffScreen.clearRect(, , AppletWidth, AppletHeight); // // Bildschirm löschen für (int i = ; i < MAX; i++) { drawOffScreen.setColor(p[i] . color); // RGB-Farbe drawOffScreen.fillOval(p[i].x, p[i].y, SIZE, SIZE); p[i].x += p[i].mx; p[i].y += p[i].my; // if (p[i].x > AppletWidth || p[i].y > AppletHeight) { // p[i].reset(); // } int x = p[i].x; int R = p[i].color.getRed( ); // Farbe extrahieren int G = p[i].color.getGreen(); int B = p[i].color.getBlue(); while (true) { if (R == && G == && B == ) { break; } R -= COLORLV; // Schwanzfarbe ausblenden, wenn (R < ) { R = ; { B = ; } Farbe color = new Color(R, G, B); x -= p[i].mx; // Cover the tail y -= p[i].my; drawOffScreen .fillOval(x, y, SIZE, SIZE); } if (x > AppletWidth || y > AppletHeight) { // Der Meteor fliegt aus dem Fenster, setze den Meteor zurück p[i].reset(); } } repaint(); try { Thread.sleep(SLEEP) { // TODO Automatisch generierter Catch-Block e.printStackTrace (); } } } class Meteor { // Meteor class int x, y; // Meteor position int mx, my; color; // Meteorfarbe public Meteor() { reset(); } public void reset() { int rand = (int) (Math.random() * ); = (int) (Math.random() * ); y = ; } else { y = (int) (Math.random() * ); (Math.random() * + ); // Fallgeschwindigkeit und Winkel zufällig generieren my = (int) (Math.random() * + ); if (COLOR == null || COLOR.length() == ) { color = new Color( // Zufällige Farbe (new Double(Math.random() * )).intValue() + , (new Double(Math.random() * )).intValue() + , (new Double(Math.random() * )).intValue() + } else { color = Color.decode(COLOR);Der obige Code ist der reine Java-Code, den Sie in diesem Artikel zum Implementieren von Meteoren am Himmel erhalten. Ich hoffe, dass das Teilen dieses Artikels Ihnen unerwartete Vorteile bringen kann.