求一个java 用JFrame做的 下流星雨的小案例,在线等 这个不难的吧 循环改变位置 判断到底了.重新开始....会点spring 能写的. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 手动画吧。用Griphcs2D定时重新画线。 Java 2D Graphics + 你的艺术创意 import java.awt.BorderLayout;import java.awt.Canvas;import java.awt.Color;import java.awt.Graphics;import java.awt.Image;import java.util.ArrayList;import java.util.Random;import javax.swing.JFrame;public class DrawSquare3 extends JFrame implements Runnable { Canvas canvas = new Canvas(); public DrawSquare3() { this.setSize(800, 800); canvas.setSize(this.getSize().width, this.getSize().height); this.getContentPane().add(canvas, BorderLayout.CENTER); this.pack(); canvas.setBackground(Color.BLACK); this.setVisible(true); } ArrayList<Rain> rainlist = new ArrayList<DrawSquare3.Rain>(); Random random = new Random(); public void paint(){ Image image = createImage(this.getSize().width, this.getSize().height); Graphics g = image.getGraphics(); g.setColor(Color.black); g.fillRect(0, 0, this.getSize().width, this.getSize().height); for(int i = 0; i < 10; i++){ rainlist.add(new Rain(getSize().width/4+random.nextInt()%(getSize().width+getSize().width/4))); } for(int i = 0; i < rainlist.size(); ){ rainlist.get(i).paint(g); if(rainlist.get(i).y > this.getSize().height){ rainlist.remove(i); } else { i++; } } canvas.getGraphics().drawImage(image, 0, 0, null); } class Rain { public int x, y; public Rain(int x){ this.x = x; this.y = 0; } public void paint(Graphics g){ g.setColor(Color.yellow); g.drawLine(x+20, y-50, x, y); x-=5; y+=20; } } public void run(){ while(true){ try { paint(); Thread.sleep(30); } catch (Exception e) { e.printStackTrace(); } } } public static void main(String[] args) { (new Thread(new DrawSquare3())).start(); }}雨的效果改Rain的paint背景的效果改DrawSquare3的paint 数组溢出异常 Java代码运行时间问题 访问匿名内部类的方法 java处理sql中的图片字段 Socket编程中InputStream读取数据的问题 一直不明白的一个问题!多继承和接口 10个对象有属性一起提交怎么保存数据库,用JDBC 浙大翁恺JAVA视频课程。 我的尚学堂坦克大战网络版 对方坦克动不了,请大牛们分析分析 To: ALL 我最近很有空在研究代码。谁和我一起啊???? eclipse jdk1.8 @override 错误 关于$.post传值到action的乱码问题
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Random;import javax.swing.JFrame;public class DrawSquare3 extends JFrame implements Runnable {
Canvas canvas = new Canvas();
public DrawSquare3() {
this.setSize(800, 800);
canvas.setSize(this.getSize().width, this.getSize().height);
this.getContentPane().add(canvas, BorderLayout.CENTER);
this.pack();
canvas.setBackground(Color.BLACK);
this.setVisible(true);
}
ArrayList<Rain> rainlist = new ArrayList<DrawSquare3.Rain>();
Random random = new Random();
public void paint(){
Image image = createImage(this.getSize().width, this.getSize().height);
Graphics g = image.getGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, this.getSize().width, this.getSize().height);
for(int i = 0; i < 10; i++){
rainlist.add(new Rain(getSize().width/4+random.nextInt()%(getSize().width+getSize().width/4)));
}
for(int i = 0; i < rainlist.size(); ){
rainlist.get(i).paint(g);
if(rainlist.get(i).y > this.getSize().height){
rainlist.remove(i);
} else {
i++;
}
}
canvas.getGraphics().drawImage(image, 0, 0, null);
}
class Rain {
public int x, y;
public Rain(int x){
this.x = x;
this.y = 0;
}
public void paint(Graphics g){
g.setColor(Color.yellow);
g.drawLine(x+20, y-50, x, y);
x-=5;
y+=20;
}
}
public void run(){
while(true){
try {
paint();
Thread.sleep(30);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
(new Thread(new DrawSquare3())).start();
}
}
雨的效果改Rain的paint
背景的效果改DrawSquare3的paint