我想做一个applet时时与数据库通讯,把数据库中的值提出来,页面上再用一个图片根据提出的值定点移动.数据库提出的值可以换成屏幕坐标,怎样才能让这个图片时时移动,以及怎样让applet时时和数据库通信呢?最好有源程序.

解决方案 »

  1.   

    我是想用servlet里写一个timer函数不停地从数据库中扫描结果,再把这个结果传到applet里面去,applet再重画这个点的位置对吗?
      

  2.   

    能实时与数据库通信,就能实时移动图片,只要repaint就行了
      

  3.   

    //程序有点问题,刷新的时间好像不对,哪位知道啊import javax.swing.*;
    import java.awt.*;
    import java.util.*;public class AlwaysMove extends JApplet implements Runnable{
    private Random rnd = new Random();
    public void init(){
    this.setSize(new Dimension(600,400));
    this.setVisible(true);
    }

    public void start(){
    Thread thread = new Thread(this);
    thread.start();
    }

    public void run(){
    while(true){
    try{
    Thread.sleep(500);
    }catch(InterruptedException e){
    JOptionPane.showMessageDialog(null,"InterruptedException");
    }
    repaint();
    }
    }

    public void update(Graphics g){
    paint(g);
    }

    public void paint(Graphics g){
    super.paint(g);
    int x = rnd.nextInt(500);
    int y = rnd.nextInt(300);
    g.drawImage(getImage(getCodeBase(),"1.gif"),x,y,this);

    }
    }
      

  4.   

    都不会吗,哎我可怎么办呢?我想用xmlhttp但是不管用....不知道applet能不能搞定?