java雨花特效代码 java下雨特效

跨年特效代码

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 = 0; i Max_Number; i++)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 = 0; i Max_Number; i++)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 = 0; i Max_Number; i++) {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 = 0; i patch; i++) {Ex[i] = (int) (Math.random() * energy) - energy / 2;Ey[i] = (int) (Math.random() * energy * 7 / 8) - energy / 8;

创新互联网站建设提供从项目策划、软件开发,软件安全维护、网站优化(SEO)、网站分析、效果评估等整套的建站服务,主营业务为网站设计制作、成都做网站,重庆App定制开发以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。创新互联深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

回答于 2023-02-22

向TA提问

官方服务

官方网站

官方网站

求java公告栏特效代码

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class Test{

private JFrame frame;

private String scrolledText;

private String str ="滚动文字 Demo";

public static void main(String args[]) {

try{

Test window = new Test();

window.frame.setVisible(true);

}

catch(Exception e){

e.printStackTrace();

}

}

public Test(){

initialize();

}

private void initialize(){

frame.setBounds(100, 100, 500, 375);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

final JPanel panel = new JPanel();

panel.setBackground(Color.WHITE);

panel.setLayout(new BorderLayout());

frame.getContentPane().add(panel, BorderLayout.NORTH);

final JLabel label = new JLabel();

label.setText("New JLabel");

panel.add(label);

label_scrolledText(label);

frame.addComponentListener(

new ComponentAdapter(){

public void componentResized(ComponentEvent arg0){

label_scrolledText(label);

}

});

}

public void label_scrolledText(JLabel label) {

this.scrolledText = this.str;

label.setText(scrolledText);

FontMetrics metrics = label.getFontMetrics(label.getFont());

int textW = metrics.stringWidth(label.getText());

Dimension frameSize = frame.getSize();

for (int i = 1; i = (frameSize.width - textW) / 3 - 3; i++)

scrolledText += " ";

label.setText(scrolledText);

Thread thread = new Thread(new TextChanger(label));

thread.start();

}

}

java.lang.NullPointerException

at Test.initialize(Test.java:26)

at Test.init(Test.java:23)

at Test.main(Test.java:16)

java 能否实现桌面下雪花的效果?使用swing?

/*

*实现在窗体上随机布满300个雪花("*"),滚动

*在上次的课基础上增加了for循环(一次要产生300个变量),随机数,数组 ;

*下面的序号为步骤

*/ import java.awt.* ; //(3)导入awt包

public class Star {

public static void main(String args[]) {

Frame w = new Frame() ; //(1)绘制窗体

w.setSize(1024,768) ; //(4)把窗体布满全屏

w.setBackground(Color.BLACK) ; //(5)背景为黑颜色

MyPanel mp = new MyPanel() ; //(7)把MyPanel对象mp,添加到窗体w上

w.add(mp) ;

Thread t = new Thread(mp) ;

t.start() ; //(12)启动线程

w.show(); //(2)显示窗体

}

}

//(6)继承Panel类

class MyPanel extends Panel implements Runnable { //(11)实现Runnable接口

int x[] = new int[300] ;

int y[] = new int[300] ; //(8)定义300个数组变量 MyPanel(){

for(int i = 0;i 300; i++) {

x[i] = (int)(Math.random()*1024) ;

y[i] = (int)(Math.random()*768) ; //(9)当程序走到第6步的时候程序就会调用构成函数

} //由于随机数是从0-1之间的数任意产出所以x乘以1024,y乘以768再转换为int类型

}

public void paint(Graphics g) {

for(int i = 0;i 300; i++) {

g.setColor(Color.WHITE) ;

g.drawString("*",x[i],y[i]) ;

//g.drawString("*",30,30) ;(7)绘制一个星星在屏幕的x=30,y=30的位置上

} //(10)绘制300个雪花,把坐标30,30,改成x[i],y[i] ;

} //做到这步可以实现在黑色的天空布满300个星星

public void run() {

while(true) { //(13)实现产生300个雪花往下落死循环

for(int i = 0 ; i 300; i++) {

y[i]++ ; //(14)y坐标不断的+1

if(y[i] 768){ //(18)如果y轴坐标大于768时,则y = 0,回到窗体的顶部

y[i] = 0 ;

}

}

try{ //(16)用try,catch解决线程休眠的异常

Thread.sleep(20) ; //(15)在每次y轴坐标+1后线程休眠20毫秒

}catch(Exception e) {}

repaint() ; //(17)雪花在新的位置重画

}

}

}

页面特效:下星星的代码(JAVA代码)

以下的代码就可以,lz自己在*的地方填入星星的图片就可以了

body bgcolor=#ee3300

style

.drop { position: absolute; width: 3; filter: flipV(), flipH(); font-size: 40; color: #ffffff }

/style

script language="javascript"

snow = false; // false-rain; true-snow

snowsym = " * " are the symbols for each

rainsym = " * " can put images here.

howmany = 20 many drops/snowflakes?

/**************Do not need to change anything below***********/

if(snow){sym = snowsym; speed=1; angle=10; drops=howmany}

else{sym = rainsym; speed=30; drops=howmany; angle=6}

movex = -speed/angle; movey = speed; count = 0;

function moverain(){

for(move = 0; move drops; move++){

xx[move]+=movex; yy[move]+=mv[move];

hmm = Math.round(Math.random()*1);

if(xx[move] 0){xx[move] = maxx+10;}

if(yy[move] maxy){yy[move] = 10;}

drop[move].left = xx[move]

drop[move].top = yy[move]+document.body.scrollTop;

}setTimeout('moverain()','1')}

/script

script language="javascript"

if (document.all){

drop = new Array(); xx = new Array(); yy = new Array(); mv = new Array()

ly = "document.all[\'"; st = "\'].style"

for(make = 0; make drops; make++){

document.write('div id="drop'+make+'" class=drop'+sym+'/div');

drop[make] = eval(ly+'drop'+make+st);

maxx = document.body.clientWidth-40

maxy = document.body.clientHeight-40

xx[make] = Math.random()*maxx;

yy[make] = -100-Math.random()*maxy;

drop[make].left = xx[make]

drop[make].top = yy[make]

mv[make] = (Math.random()*5)+speed/16;

drop[make].fontSize = (Math.random()*10)+20;

if(snow){col = 'white'}else{col = 'white'}

drop[make].color = col;

}

window.onload=moverain

}

/script

/body


本文标题:java雨花特效代码 java下雨特效
当前链接:http://azwzsj.com/article/ddcegdh.html