import javax.swing.*; import java.awt.*; public class Main { public static void main(String args[]) { for(int i=0;;i++) { jframe frame = new jframe(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); try { Thread.currentThread().sleep(500);// 毫秒 停留500毫秒 } catch (Exception e) { } } } } class jframe extends JFrame { public jframe() { setBounds(300, 100, 500, 500); getContentPane().setBackground(Color.BLACK); 设置背景 Stars s = new Stars(); add(s); } } class Stars extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setPaint(Color.green); String star = "★"; setBackground(Color.BLACK); for (int i = 0; i < 60; i++) { x[i] = (int) (Math.random() * 500); y[i] = (int) (Math.random() * 500); g2.drawString(star, x[i], y[i]); } } int x[] = new int[100]; int y[] = new int[100]; }
用JAVA写一个星递减_java 一个简单的程序 夜空中的星
最新推荐文章于 2021-10-31 17:30:30 发布