This article describes the Java implementation of the Stars effect method. Share to everyone for your reference.
The specific implementation code is as follows:
Copy Code code as follows:
Import java.awt.*;
Public class Main {
public static void Main (string[] args) {
Frame frame = new Frame ("stars") ;
mypanel Panel = new Mypanel ();
Frame.add (panel) ;
Frame.setbackground (Color.Black);
Frame.setsize ( 1024, 768);
frame.setvisible (true);
}
}
Class Mypanel extends Panel {
Private static final long serialversionuid = 1L;
public void Paint (Graphics g) {
G.setcolor (Color.White);
for (int i = 0; i < i++) {
g.DrawString ("*", (int) (Math.random () * 1024),
(int) (Math.random () * 768));
}
G.filloval (800, 100, 100, 100);
G.setcolor (Color.Black);
G.filloval (780, 80, 100, 100);
}
}
The effect is as shown in the following illustration:
I hope this article will help you with your Java programming.