要实时作图?1。动态图:最好用applet,可以和servlet通过http tunneling传serialized object,画图很方便(做过,有体会)。2。静态图:继承一个JFrame,然后取得graphics,画图。再用acme的组件编码成jpg,传回去。这个我也做过,封成了taglib,做任意曲线。不过有限制。在linux/unix系统下,要配置DISPLAY参数。据说jdk1.4会有改变,不过我试过beta版,问题依旧。

解决方案 »

  1.   

    to miles_z(www.2yup.com/asp/):
    我要做的是实时图。
    恕我粗浅,http tunneling传serialized object是什么?能不能给个例子?
      

  2.   

    jfreechart到底怎么用?我下了,但是根据他的说明,还是运行不起来!
    那位仁兄用过?过来帮帮我!
      

  3.   

    很简单的。在servlet的doGet里,设一下contentType:
    response.setContentType("application/x-java-serialized-object");输出用:
    ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
    out.writeObject(new Double("123.4"));
    out.flush();就把对象写出去了。在applet,用:      URL url = new URL(protocol,host,port,this.sufix);
          URLConnection conn = url.openConnection();
          conn.setUseCaches(false);
          ObjectInputStream in = new ObjectInputStream(conn.getInputStream());      Object obj = in.readObject();
    简单吧,呵呵。
      

  4.   

    to miles_z(www.2yup.com/asp/):
    servlet只处理读取和传输数据,然后Applet接受数据,并进行绘图,是这样吗?这样速度快不快?
    能不能给出个具体的例子?
      

  5.   

    在WEB上显示为什么不用javascript来实现呢,applet的话在IE6上面你还得让用户安装vm装一不小心装上sun公司的许多东东还用不了
      

  6.   

    速度尚可。要实时刷新,只能这样了。internet上的applet过不了firewall,读不到东西。这一经是个简单例子了。不用怎么改就行。再写,就不通用了。对了,你的servlet要实现SingleThreadModel接口,免得有问题。gud luck
      

  7.   

    呵呵,这些东东我都没有想到过,因为我对java不熟,但是人家要求必须用jsp做,否则格杀勿论。???苦啊!:(
    能不能给个画图的例子,没办法了,兄弟就在帮我一把,到时分全给你了!
      

  8.   

    OK,给你个完整的例子:package applets;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    import com.borland.jbcl.layout.*;/**
     * <p>Title: Allowance Trading System</p>
     * <p>Description: The Allowance Trading System.</p>
     * <p>Copyright: Copyright (c) 2001</p>
     * <p>Company: Yup Studio</p>
     * @author Miles.Z
     * @version 1.07
     */public class RateEstimateMonitor extends Applet implements Runnable{
      boolean isStandalone = false;
      XYLayout xYLayout1 = new XYLayout();
      Panel panel1 = new Panel();
      Panel panel2 = new Panel();
      Label label1 = new Label();  /**server param*/
      String protocol;
      String host;
      int port;  String sufix;
      String destination;
      boolean looping = true;  //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public RateEstimateMonitor() {}  //Initialize the applet
      public void init() {
        sufix = this.getParameter("sufix", "");
        destination = this.getParameter("destination","");
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }    URL CurPage = getCodeBase();
        protocol = CurPage.getProtocol();
        host = CurPage.getHost();
        port = CurPage.getPort();
    //    protocol = "http";
    //    host = "localhost";
    //    port = 8080;    // start up.
        Thread t = new Thread(this);
        t.start();  }
      //Component initialization
      private void jbInit() throws Exception {
        this.setLayout(xYLayout1);
        this.setBackground(new Color(255, 255, 190));
        this.setFont(new java.awt.Font("SansSerif", 0, 12));
        panel1.setBackground(Color.white);
        panel2.setBackground(Color.blue);
        xYLayout1.setWidth(237);
        xYLayout1.setHeight(41);
        label1.setAlignment(1);
        this.add(panel1,    new XYConstraints(2, 2, 231, 17));
        this.add(panel2,   new XYConstraints(1, 1, 233, 19));
        this.add(label1,  new XYConstraints(71, 21, 87, 15));
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  public void checkRate() {
        try{
          URL url = new URL(protocol,host,port,this.sufix);
          URLConnection conn = url.openConnection();
          conn.setUseCaches(false);
          ObjectInputStream in = new ObjectInputStream(conn.getInputStream());      Object obj = in.readObject();
          if(obj!=null) {
            Double Rate = (Double)obj;
            if(Rate.doubleValue()==1.0) looping = false;
            repaintLabel(Rate);
            repaintPanel(Rate);
            System.err.println("===");
            System.err.println(Rate.doubleValue());
          }      in.close();    } catch(Exception ex) {
          looping = false; // stop.
          System.err.println(ex.toString());
        }
      }  public void repaintLabel(Double Rate) {
        int rate = (int)(Rate.doubleValue()*100);
        label1.setText(rate+"%");
        label1.repaint();
      }  public void repaintPanel(Double Rate) {
        double rate = Rate.doubleValue();    Graphics g = this.panel1.getGraphics();
        g.clearRect(0,panel1.getSize().width,panel1.getSize().width,panel1.getSize().height);
        g.setColor(new Color(144,144,255));
        g.fillRect(1,1,(int)((panel1.getSize().width-2)*rate),panel1.getSize().height-2);
      }  public void run() {
        while(looping) {
          checkRate();
          try{
            Thread.currentThread().sleep(100);
          } catch(InterruptedException ex) {}
        }    try {
          URL url = new URL(protocol,host,port,destination);
          getAppletContext().showDocument(url);
        } catch(MalformedURLException ex) {
        }
      }
    }
    这个applet用来显示一个进度尺。
    93-98行读了从http-tunneling传来的一个Integer对象(也就是一个整数了),紧接着就重绘了进度尺(fillRect,128)和label(setText,118)。
    另外,我用的layout是borland的。你可以就用简单的,像borderLayout。至于servlet端,我给你的那几行放到doGet里就行了。gud luck!
      

  9.   

    没装JBuilder好象找不到com.borland.jbcl.layout.*吧,我是没成功
      

  10.   

    com.borland.jbcl.layout.*,的确,要加入新的包,烦,烦,烦。关键你还不一定能找到,如果手头没有JBuilder的话。
      

  11.   

    是啊。改改别用就行了。我是懒的用baggrid什么的。
      

  12.   

    还是谢谢大家!先结了吧!气死我了,需求又变了,现在不要我用applet画了!正是郁闷!!!!!
    有关这个问题,大家请到http://www.csdn.net/expert/topic/945/945722.xml?temp=.3982202
    继续关照!