首页 > 代码库 > 练习.繁星点点
练习.繁星点点
1 package com.java7.mystarandmoon.main; 2 import java.awt.*; 3 import javax.swing.JFrame; 4 import javax.swing.JPanel; 5 6 7 public class MyStarAndMoon { 8 public static void main(String[] args) { 9 JFrame w = new JFrame();10 11 w.setTitle("MyStarAndMoon");12 w.setSize(1024, 768);13 14 MyPanel mp = new MyPanel();15 w.add(mp);16 17 Thread t = new Thread(mp);18 t.start();19 20 w.setVisible(true);21 22 23 }24 }25 26 @SuppressWarnings("serial")27 class MyPanel extends JPanel implements Runnable {28 int x[] = new int[300];29 int y[] = new int[300];30 int fx[] = new int[300];31 int fy[] = new int[300];32 33 public MyPanel() {34 for(int i = 0; i < 300; i++) {35 x[i] = (int)(Math.random() * 1024);36 y[i] = (int)(Math.random() * 768);37 }38 }39 public void paint(Graphics g) {40 super.paint(g);41 this.setBackground(Color.BLACK);42 for (int i = 0; i < 100; i++) {43 g.setColor(Color.YELLOW);44 g.setFont(new Font("", (int)(Math.random() * 15), (int)(Math.random() * 15)));45 g.drawString(".", x[i], y[i]); 46 }47 g.setColor(Color.WHITE);48 g.drawOval(30, 30, 100, 100);49 g.fillOval(30, 30, 100, 100);50 g.setColor(Color.BLACK);51 g.drawOval(50, 30, 100, 100);52 g.fillOval(50, 30, 100, 100);53 }54 public void run() {55 while(true) {56 try {57 Thread.sleep(40);58 } catch (Exception e) {59 60 }61 repaint();62 }63 }64 }
练习.繁星点点
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。