标签:
使用画布和画笔绘制一个满天星的小程序,十分简单,适合初学者学习使用:
import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.Panel; public class DrawStar { public static void main(String[] args) { Frame frame=new Frame(); frame.setSize(1024, 768); frame.setBackground(Color.BLACK); MyPanel myPanel=new MyPanel(); frame.add(myPanel); frame.show(); } } class MyPanel extends Panel{ @Override public void paint(Graphics g) { g.setColor(Color.WHITE); for (int i = 0; i < 300; i++) { g.drawString("*", (int)(Math.random()*1024), (int)(Math.random()*768)); } super.paint(g); } }
标签:
原文地址:http://blog.csdn.net/yayun0516/article/details/50807543