本文实例讲述了java实现满天星效果的方法。分享给大家供大家参考。
具体实现代码如下:
public class Main {
public static void main(String[] args) {
Frame frame = new Frame(\"满天星\");
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 < 300; 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);
}
}
本文地址:https://www.stayed.cn/item/6106
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我