HTML
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比湘潭县网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式湘潭县网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖湘潭县地区。费用合理售后完善,十载实体公司更值得信赖。
HEAD
META name="cenlertor" content="microsoft frontpage5.0"
META name="ProgId" content="Frontpage.editor.Document"
title图片闪烁/title
script language="JavaScript"
function blink()
{ angel.style.visibility=(angel.style.visibility=="visible") ? "hidden" : "visible";
setTimeout("blink()",500);
}
/script
HEAD
body onLoad="blink()"
img id=angel src="14045015.gif" align="center"
/body
HTML
这样就可以了,
1、因为调用了repaint方法,或者调用repaint(x,y,w,h)局部刷新
2、可调用java 的awt/swing控件,下面贴一个示例代码:
public static void main(String args[]){
JFrame jf = new JFrame();
jf.getContentPane().setLayout(new FlowLayout());
jf.getContentPane().add(new JButton("测试"));
jf.setSize(320, 240);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
解决绘图时屏幕闪耀现象:
重写控件paint()方法,绘图时会出现屏幕闪耀,为了避免这种情况,可以重写update()方法,并在update()方法中调用paint()方法。
package panel;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JPanel;
import main.MainTank;
public class TipPanel extends JPanel implements Runnable{
/**
*
*/
private static final long serialVersionUID = 1L;
//偶数打印,画面板
int time=0;
public void paintComponent(Graphics g){
super.paint(g);
g.fillRect(0, 0, MainTank.getWidthOfGame(), MainTank.getHeightOfGame());//绘制提示窗口
if (time%2==0){//偶数打印,画面板,造成闪烁效果
g.setColor(Color.ORANGE);
Font font=new Font("华文楷体",Font.BOLD,30);
g.setFont(font);//选用字体
g.drawString("Ready", 140, 130);
}
}
@Override
public void run() {
while (true){
try{
Thread.sleep(250);
}catch (Exception e){
e.getMessage();
}
time++;//绘图开关
this.repaint();
}
}
}//TipPanel
类似的,修改下就行
Java程序:
import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main extends JFrame implements Runnable {
JButton btn;
public Main() {
super("闪烁的按钮");
this.setSize(300, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
btn = new JButton("我会闪烁");
this.add( btn);
Thread th = new Thread(this);
th.start();
}
public static void main(String[] args) {
new Main();
}
@Override
public void run() {
int r = 127;
int g = 127;
int b = 127;
int i, j, k;
Random rand = new Random();
while(true) {
i = rand.nextInt(255);
j = rand.nextInt(255);
k = rand.nextInt(255);
r = (r + i) % 255 + 1;
g = (g + j) % 255 + 1;
b = (b + k) % 255 + 1;
btn.setBackground(Color.getHSBColor(r, g, b));
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
运行该程序后,可以看到按钮的背景会持续闪烁。