把下面的代碼放在 body 標(biāo)簽下,圖片路徑修改成自己的
平山ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
table width="1024" border="0"
tr
td height="200"DIV id=demo style="OVERFLOW: hidden; WIDTH:1024px; HEIGHT: 200px" align=center
TABLE cellSpacing=0 cellPadding=0 align=left border=0 cellspace="0"
TBODY
TR
TD id=demo1 vAlign=top
table width="1024" border="0" align="center" cellpadding="0" cellspacing="0"
tr
td width="250"img src="images/pic/1.gif" width="250" height="200"/td
td width="250"img src="images/pic/2.gif" width="250" height="200"/td
td width="250"img src="images/pic/3.gif" width="250" height="200"/td
td width="250"img src="images/pic/4.gif" width="250" height="200"/td
td width="250"img src="images/pic/5.gif" width="250" height="200"/td
td width="250"img src="images/pic/6.gif" width="250" height="200"/td
td width="250"img src="images/pic/7.gif" width="250" height="200"/td
td width="250"img src="images/pic/8.gif" width="250" height="200"/td
td width="250"img src="images/pic/9.gif" width="250" height="200"/td
td width="250"img src="images/pic/10.gif" width="250" height="200"/td
/table /TD
TD id=demo2 vAlign=top/TD/TR/TBODY
/TABLE
/DIV
div align="center"
SCRIPT
var speed=1
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo2.offsetWidth-demo.scrollLeft=0)
demo.scrollLeft-=demo1.offsetWidth
else{
demo.scrollLeft++
}
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
/SCRIPT
/div
/td
/tr
/table
import java.applet.Applet;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;public class Welcome extends Applet {
int pos = 0;
Image graph;
int w=0;
String str = "熱烈歡迎2009屆新生入學(xué)";
Font f = new Font("黑體", Font.BOLD, 20);
public Welcome(){
FontMetrics fm = getFontMetrics(f);
w = fm.stringWidth(str);
pos=w;
}
public void paint(Graphics g) {
g.setFont(f);
g.drawString(str, pos-w, 40);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
pos = pos + 5;
if (pos-w getWidth())
pos = w;
repaint();
}
}
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JWindow;
import javax.swing.Timer;
public class Marquee extends JWindow {
public static String marqueeText;
public static Marquee myMarquee = new Marquee("嗚嗚~,跑馬燈動(dòng)不了了~ ");
public static JLabel myJLabel = new JLabel(myMarquee.toString());
// 實(shí)例化,否則nullpoint
public static Point anchor = new Point();
public Marquee(String marquee) {
marqueeText = marquee;
}
public static void main(String[] args) {
Timer marquee = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e) {
Point extSize = myMarquee.getLocation();
Dimension viewSize = myJLabel.getPreferredSize();
anchor.x += 5;// 設(shè)置移動(dòng)的速度
myMarquee.setLocation(anchor);
if (anchor.x viewSize.width) {
anchor.x = -extSize.x;
}
}
});
myJLabel.setForeground(Color.RED);
myJLabel.setOpaque(true);
myJLabel.setPreferredSize(new Dimension(1024, 30));
myMarquee.setVisible(true);
myMarquee.setLocation(0, 0);
myMarquee.setAlwaysOnTop(true);
myMarquee.add(myJLabel);
myMarquee.pack();
// 關(guān)鍵一句,你設(shè)置了定時(shí)器,但沒有讓它運(yùn)行起來,start即可
marquee.start();
}
public String toString() {
return marqueeText;
}
}
把問題分開來解決:
1.跑馬燈效果,這個(gè)是js范疇,可以找一些js組件或直接用html的marque實(shí)現(xiàn)。
2.ajax刷新可以用setIterval實(shí)現(xiàn)定時(shí)訪問,然后把服務(wù)端返回?cái)?shù)據(jù)用js加到頁面。
3.java服務(wù)端就是從數(shù)據(jù)庫或遠(yuǎn)程服務(wù)獲取數(shù)據(jù)然后組織為xml或json返回給ajax客戶端。