
import java.applet.*
import java.awt.event.*
import javax.swing.*
public class Fireworks extends Applet implements MouseListener, Runnable {
int x, y//记录鼠标点击的坐标
int top, point//好像没用到
public void init() {
x = 0
y = 0
setBackground(Color.black)// 设置背景色为黑色
addMouseListener(this)//添加鼠标监听
}
public void paint(Graphics g) {
}
public static void main(String args[]) {
Fireworks applet = new Fireworks()
JFrame frame = new JFrame("TextAreaNew")
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {//右上角的叉
System.exit(0)
}
})
frame.add(applet, BorderLayout.CENTER)
frame.setSize(800, 400)//程序的框框大小
applet.init()
applet.start()
frame.setVisible(true)//
}
public void run() {
// 变量初始化
Graphics g1
g1 = getGraphics()//这是画笔,得到一个画笔
int y_move, y_click, x_click
int v//用于计算等待的时间
x_click = x
y_click = y//把点击的坐标中败保存下来,因为其它线程会去改这两个坐标。
y_move = 400//用来计算变动的那个点,现在是屏幕的最大高度
v = 3
int r, g, b
while (y_move > y_click)//如果点击的位置小于最大高度。
{
g1.setColor(Color.black)//画笔设成黑色
g1.fillOval(x_click, y_move, 5, 5)//画圆,圆点在点击的X轴,程序界面的最高点,长为5,宽为5
y_move -= 5//最高点-5
r = (((int) Math.round(Math.random() * 4321)) % 200) + 55
g = (((int) Math.round(Math.random() * 4321)) % 200) + 55
b = (((int) Math.round(Math.random() * 4321)) % 200) + 55//rgb是光的三原色,这个就是烟花产生的颜色,这里定义成随机的,但在一个范围里
g1.setColor(new Color(r, g, b))//把画笔改成那个颜色
g1.fillOval(x_click, y_move, 5, 5)//画一个亮拿这样的圆
for (int j = 0 j <= 10 j++) {
if (r > 55)
r -= 20
if (g > 55)
g -= 20
if (b > 55)
b -= 20
g1.setColor(new Color(r, g, b))
g1.fillOval(x_click, y_move + j * 5, 5, 5)//这一段都是改变颜色,然后画圆的
}
g1.setColor(Color.black)
g1.fillOval(x_click, y_move + 5 * 10, 5, 5)//把上一次画的彩色圆,用黑色画一遍,就能让它消失在背景里
try {
Thread.currentThread().sleep(v++)//让程序等一下,让你看到效果,不然画完的东西一下就不见了,你看不清。
} catch (InterruptedException e) {
}
}//上面这段代码是烟花的升上去的那一串东西的卖键颤效果
for (int j = 12 j >= 0 j--) {
g1.setColor(Color.black)
g1.fillOval(x_click, y_move + (j * 5), 5, 5)
try {
Thread.currentThread().sleep((v++) / 3)
} catch (InterruptedException e) {
}
}//让最后的那串东西的点消失
y_move = 400
g1.setColor(Color.black)
while (y_move > y_click) {
g1.fillOval(x_click - 2, y_move, 9, 5)
y_move -= 5
}//这段不太清楚是干什么的,我把它去掉,看不出效果的变化
v = 15
for (int i = 0 i <= 25 i++) {
r = (((int) Math.round(Math.random() * 4321)) % 200) + 55
g = (((int) Math.round(Math.random() * 4321)) % 200) + 55
b = (((int) Math.round(Math.random() * 4321)) % 200) + 55
g1.setColor(new Color(r, g, b))
g1.drawOval(x_click - 3 * i, y_click - 3 * i, 6 * i, 6 * i)
if (i < 23) {
g1.drawOval(x_click - 3 * (i + 1), y_click - 3 * (i + 1),
6 * (i + 1), 6 * (i + 1))
g1.drawOval(x_click - 3 * (i + 2), y_click - 3 * (i + 2),
6 * (i + 2), 6 * (i + 2))
}//上面这段是画爆炸的效果
try {
Thread.currentThread().sleep(v++)//停一下,看效果
} catch (InterruptedException e) {
}
g1.setColor(Color.black)
g1.drawOval(x_click - 3 * i, y_click - 3 * i, 6 * i, 6 * i)//然后画黑圈,相当于让彩圈消失。
}
}
public void mousePressed(MouseEvent e) {//点击从这里开始~~~~~~~~~~~~~~
x = e.getX()
y = e.getY()//得到鼠标点击的坐标
Thread one = new Thread(this)//新建一个线程
one.start()//启动这个线程,到上面的run方法
one = null//把这个线程置为空,让它执行完以后就释放
}
如果你想一下自己写要怎样写这个程序,就很容易理解这个程序了。
一直从下向上画圆,然后把下面的圆擦掉,就能得到一个向上升的烟花效果,
爆炸效果就是先画小圆再画大圆,然后擦掉小圆,再擦掉大圆。
这个是比较有名的那个烟花,不知道你有没有用:建个工程,以Fireworks为类即可
import java.awt.*
import java.applet.*
import java.awt.event.*
import javax.swing.*
public class Fireworks extends Applet implements MouseListener,Runnable
{
int x,y
int top,point
/**
*对小程序进行变量和颜神陵首色的初始游数化。
*/
public void init()
{
x = 0
y = 0
//设置背景色为黑色
setBackground(Color.black)
addMouseListener(this)
}
public void paint(Graphics g)
{
}
/**
*使该程序可以作为应用程序运行汪巧。
*/
public static void main(String args[]) {
Fireworks applet = new Fireworks()
JFrame frame = new JFrame("TextAreaNew")
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0)
}
})
frame.getContentPane().add(
applet, BorderLayout.CENTER)
frame.setSize(800,400)
applet.init()
applet.start()
frame.setVisible(true)
}
/**
*程序主线程,对一个烟花进行绘制。
*/
public void run()
{
//变量初始化
Graphics g1
g1 = getGraphics()
int y_move,y_click,x_click
int v
x_click = x
y_click = y
y_move = 400
v = 3
int r,g,b
while(y_move >y_click)
{
g1.setColor(Color.black)
g1.fillOval(x_click,y_move,5,5)
y_move -= 5
r = (((int)Math.round(Math.random()*4321))%200)+55
g = (((int)Math.round(Math.random()*4321))%200)+55
b = (((int)Math.round(Math.random()*4321))%200)+55
g1.setColor(new Color(r,g,b))
g1.fillOval(x_click,y_move,5,5)
for(int j = 0 j<=10j++)
{
if(r>55) r -= 20
if(g>55) g -= 20
if(b>55) b -=20
g1.setColor(new Color(r,g,b))
g1.fillOval(x_click,y_move+j*5,5,5)
}
g1.setColor(Color.black)
g1.fillOval(x_click,y_move+5*10,5,5)
try
{
Thread.currentThread().sleep(v++)
} catch (InterruptedException e) {}
}
for(int j=12j>=0j--)
{
g1.setColor(Color.black)
g1.fillOval(x_click,y_move+(j*5),5,5)
try
{
Thread.currentThread().sleep((v++)/3)
} catch (InterruptedException e) {}
}
y_move = 400
g1.setColor(Color.black)
while(y_move >y_click)
{
g1.fillOval(x_click-2,y_move,9,5)
y_move -= 5
}
v = 15
for(int i=0i<=25i++)
{
r = (((int)Math.round(Math.random()*4321))%200)+55
g = (((int)Math.round(Math.random()*4321))%200)+55
b = (((int)Math.round(Math.random()*4321))%200)+55
g1.setColor(new Color(r,g,b))
g1.drawOval(x_click-3*i,y_click-3*i,6*i,6*i)
if(i<23)
{
g1.drawOval(x_click-3*(i+1),y_click-3*(i+1),6*(i+1),6*(i+1))
g1.drawOval(x_click-3*(i+2),y_click-3*(i+2),6*(i+2),6*(i+2))
}
try
{
Thread.currentThread().sleep(v++)
} catch (InterruptedException e) {}
g1.setColor(Color.black)
g1.drawOval(x_click-3*i,y_click-3*i,6*i,6*i)
}
}
/**
*对鼠标事件进行监听。
*临听其鼠标按下事件。
*当按下鼠标时,产生一个新线程。
*/
public void mousePressed(MouseEvent e)
{
x = e.getX()
y = e.getY()
Thread one
one = new Thread(this)
one.start()
one = null
}
/**
*实现MouseListener接中的方法。为一个空方法。
*/
public void mouseReleased(MouseEvent e)
{
}
/**
*实现MouseListener接中的方法。为一个空方法。
*/
public void mouseEntered(MouseEvent e)
{
}
/**
*实现MouseListener接中的方法。为一个空方法。
*/
public void mouseExited(MouseEvent e)
{
}
/**
*实现MouseListener接中的方法。为一个空方法。
*/
public void mouseClicked(MouseEvent e)
{
}
}
烟花代码如下:
package love
import java.applet.Applet
import java.awt.Color
import java.awt.Graphics
import java.net.URL
import java.util.Random
烟花
@author enjoy
@SuppressWarnings("serial")
public class Q extends Applet implements Runnable
public int speed, variability, Max_Number, Max_Energy, Max_Patch,
Max_Length, G
public String sound
private int width, height
private Thread thread = null
private BeaClassDemo bcd[]
public void init()
int i
this.setSize(1900, 900)
width = getSize().width - 1
height = getSize().height - 1
speed = 1 // 烟花备消绽放的速度
variability = 10
Max_Number = 980 // 可发出烟花的最大数目
Max_Energy = width + 50
Max_Patch = 90 仿山知 // 最大的斑点数
Max_Length = 90 唯睁 // 斑点的最大距离
G = 150 // 向地面弯曲的力度
bcd = new BeaClassDemo[Max_Number]
for (i = 0i <Max_Numberi++)
bcd[i] = new BeaClassDemo(width, height, G)
}
public void start() {
if (thread == null) {
thread = new Thread(this)
thread.start()
}
}
@SuppressWarnings("deprecation")
public void stop() {
if (thread != null) {
thread.stop()
thread = null
}
}
@SuppressWarnings({ "unused", "static-access" })
public void run() {
int i
int E = (int) (Math.random() * Max_Energy * 3 / 4) + Max_Energy / 4 + 1
int P = (int) (Math.random() * Max_Patch * 3 / 4) // 烟花的斑点数
+ Max_Patch / 4 + 1
int L = (int) (Math.random() * Max_Length * 3 / 4) // 烟花可发射出的距离
+ Max_Length / 4 + 1
long S = (long) (Math.random() * 10000)
boolean sleep
Graphics g = getGraphics()
URL u = null
while (true) {
try {
thread.sleep(1000 / speed)
catch (InterruptedException x) {
sleep = true
for (i = 0i <Max_Numberi++)
sleep = sleep &&bcd[i].sleep
if (sleep &&Math.random() * 100 <variability) {
E = (int) (Math.random() * Max_Energy * 3 / 4) + Max_Energy / 4
+ 1
P = (int) (Math.random() * Max_Patch * 3 / 4) + Max_Patch / 4
+ 1
L = (int) (Math.random() * Max_Length * 3 / 4) + Max_Length / 4
+ 1
S = (long) (Math.random() * 10000)
for (i = 0i <Max_Numberi++) {
if (bcd[i].sleep &&Math.random() * Max_Number * L <1)
bcd[i].init(E, P, L, S)
bcd[i].start()
bcd[i].show(g)
public void paint(Graphics g)
g.setColor(Color.black)
g.fillRect(0, 0, width + 1, height + 1)
class BeaClassDemo
public boolean sleep = true
private int energy, patch, length, width, height, G, Xx, Xy, Ex[], Ey[], x,
y, Red, Blue, Green, t
private Random random
public BeaClassDemo(int a, int b, int g)
width = a
height = b
G = g
public void init(int e, int p, int l, long seed)
int i
energy = e
patch = p
length = l
// 创建一个带种子的随机数生成器
random = new Random(seed)
Ex = new int[patch]
Ey = new int[patch]
Red = (int) (random.nextDouble() * 128) + 128
Blue = (int) (random.nextDouble() * 128) + 128
Green = (int) (random.nextDouble() * 128) + 128
Xx = (int) (Math.random() * width / 2) + width / 4
Xy = (int) (Math.random() * height / 2) + height / 4
for (i = 0i <patchi++) {
Ex[i] = (int) (Math.random() * energy) - energy / 2
Ey[i] = (int) (Math.random() * energy * 7 / 8) - energy / 8
public void start
t = 0
sleep = false
public void show(Graphics g)
if (!sleep)
if (t <length)
int i, c
double s
Color color
c = (int) (random.nextDouble() * 64) - 32 + Red
if (c >= 0 &&c <256)
Red = c
c = (int) (random.nextDouble() * 64) - 32 + Blue
if (c >= 0 &&c <256)
Blue = c
c = (int) (random.nextDouble() * 64) - 32 + Green
if (c >= 0 &&c <256)
Green = c
color = new Color(Red, Blue, Green)
for (i = 0i <patchi++)
s = (double) t / 100
x = (int) (Ex[i] * s)
y = (int) (Ey[i] * s - G * s * s)
g.setColor(color)
g.drawLine(Xx + x, Xy - y, Xx + x, Xy - y)
if (t >= length / 2)
int j
for (j = 0j <2j++)
s = (double) ((t - length / 2) * 2 + j) / 100
x = (int) (Ex[i] * s)
y = (int) (Ey[i] * s - G * s * s)
g.setColor(Color.black)
g.drawLine(Xx + x, Xy - y, Xx + x, Xy - y)
常用的编程语言。
编程语言一:C语言
C语言是世界上最流行、使用最广泛的高级程序设计语言之一。在 *** 作系统和系统使用程序以及需要对硬件进行 *** 作的场合,用C语言明显优于其它高级语言,许多大型应用软件都是用C语言编写的。
编程语言二:java
Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaSE, JavaEE, JavaME)的总称。
编程语言三:c++
C++这个词在中国大陆的程序员圈子中通常被读做“C加加”,而西方的程序员通常读做“C plus plus" , "CPP”。 它是一种使用非常广泛的计算机编程语言。C++是一种静态数据类型检查的、支持多重编程范式的通用程序设计语言。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)