用servlet做后端,applet做前端,通过http tunnelling通信,传序列化对象。servlet里:Vector xxx = new Vector();
//fill vector here...
...
response.setContentType("application/x-java-serialized-object");
ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
out.writeObject(xxx);
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();
Vector xxx = (Vector)obj;然后就能画了。
//fill vector here...
...
response.setContentType("application/x-java-serialized-object");
ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
out.writeObject(xxx);
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();
Vector xxx = (Vector)obj;然后就能画了。
解决方案 »
- System.out.println(3/2>1);输出什么?
- Ftp同步工具编写?
- MyEclipse怎么汉化呢?
- 急求:两个类实现网络连接后可以调用repaint()方法么
- 如何添加JVM参数
- 请问该如何运行jsp的第一个例子啊?
- 关于java中设置文件过滤器
- 传递的是对象,但居然没有遵守引用传递的规则
- --->请注重基本功的程序员进来看看
- 语音识别应用软件相关资料?
- 关于iPlanet Web Server在Win2000Server上配置运行的问题?(在线等待,解决即给分,请进!)
- 请问各位高手Mon Sep 02 02:00:00 CST 2002 怎样转换成2002-9-2 2:00:00啊
你的意思我明白。但是实现起来很繁的。我做过写坐标系的一个servlet,一样道理,你看看吧:package graphics.curve;import java.awt.*;
import util.*;/**
* Title: Allowance Trading System
* Description: The Allowance Trading System.
* Copyright: Copyright (c) 2001
* Company: Yup Studio
* @author Miles.Z
* @version 1.07
*/public class Axis { public static final int TOP_ADD = 30;
public static final int XDIR_ADD = 15; // x-offset and y-offset.
private int xdecimal = 0;
private int ydecimal = 0;
private int xoff = 0;
private int yoff = 0;
// x/y space.
private int xspace = 15;
private int yspace = 35;
// x and y axis label.
private String xlabel = "x-label";
private String ylabel = "y-label";
// max value of x,y axis.
private double xmax = 0;
private double ymax = 0;
// direction point count.
private int xcount = 10;
private int ycount = 10;
// line color.
private Color color = CurvePainter.DEFAULT_AXIS_COLOR;
// line size.
private float linesize = 2.0f;
// has grid or not.
private boolean grid = false;
// grid color.
private Color gridcolor = CurvePainter.DEFAULT_GRID_COLOR; /**
* functions set private variables list above.
*/ protected void setXdecimal(int xdecimal) {
if(xdecimal>=0) this.xdecimal = xdecimal;
} protected void setYdecimal(int ydecimal) {
if(ydecimal>=0) this.ydecimal = ydecimal;
} protected void setXoff(int xoff) {
this.xoff = xoff;
} protected void setYoff(int yoff) {
this.yoff = yoff;
} protected void setXspace(int xspace) {
if(xspace>0) this.xspace = xspace;
} protected void setYspace(int yspace) {
if(yspace>0) this.yspace = yspace;
} protected void setXlabel(String xlabel){
if(xlabel!=null) this.xlabel = xlabel;
} protected void setYlabel(String ylabel){
if(ylabel!=null) this.ylabel = ylabel;
} protected void setXmax(double xmax) {
this.xmax = xmax;
} protected void setYmax(double ymax) {
this.ymax = ymax;
} protected void setXcount(int xcount){
if(xcount>0) this.xcount = xcount;
} protected void setYcount(int ycount){
if(ycount>0) this.ycount = ycount;
} protected void setColor(Color color) {
if(color!=null) this.color = color;
} protected void setLinesize(float linesize) {
if(linesize>1f) this.linesize = linesize;
} protected void setGrid(boolean grid) {
this.grid = grid;
} protected void setGridcolor(Color gridcolor) {
if(gridcolor!=null) this.gridcolor = gridcolor;
} /**
* main function goes here.
*/ protected void draw(Graphics2D g,Dimension dim) { int width = (int)dim.getWidth();
int height = (int)dim.getHeight(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); // draw the pipe.
g.setPaint(color);
g.setStroke(new BasicStroke(linesize)); Polygon xarrow = new Polygon();
xarrow.addPoint(xoff+XDIR_ADD+xspace,yoff+TOP_ADD-12);
xarrow.addPoint(xoff+XDIR_ADD+xspace+1,yoff+TOP_ADD-12);
xarrow.addPoint(xoff+XDIR_ADD+xspace-3,yoff+TOP_ADD+0);
xarrow.addPoint(xoff+XDIR_ADD+xspace+1+3,yoff+TOP_ADD+0); Polygon yarrow = new Polygon();
yarrow.addPoint(width-(xoff+XDIR_ADD)+12,height-yoff-yspace);
yarrow.addPoint(width-(xoff+XDIR_ADD)+12,height-yoff-yspace+1);
yarrow.addPoint(width-(xoff+XDIR_ADD),height-yoff-yspace-3);
yarrow.addPoint(width-(xoff+XDIR_ADD),height-yoff-yspace+1+3);
// x-axis
g.drawLine(xoff+XDIR_ADD+xspace,height-yoff-yspace,width-(xoff+XDIR_ADD),height-yoff-yspace);
g.fill(xarrow);
// y-axis
g.drawLine(xoff+XDIR_ADD+xspace,height-yoff-yspace,xoff+XDIR_ADD+xspace,yoff+TOP_ADD);
g.fill(yarrow); Font font = g.getFont().deriveFont(10.0f);
g.setFont(font);
g.setStroke(new BasicStroke(1.0f));
FontMetrics metrics = g.getFontMetrics(); String label = "";
double value = 0d;
int j = 0;
// draw the x axis scale. "i" is pixel,DO NOT TREATE IT LIKE ARRAY-INDEX!
for(int i=xoff+XDIR_ADD+xspace;i<=width-(xoff+XDIR_ADD);i=(int)Math.round(((xoff+XDIR_ADD+xspace)+ j*(width-(xoff+XDIR_ADD+xoff+XDIR_ADD+xspace))*1.0/xcount))) {
value = (i-(xoff+XDIR_ADD+xspace))/((width-(xoff+XDIR_ADD+xoff+XDIR_ADD+xspace))/xcount)*(xmax/xcount);
// format display.
label = StringKit.formatNumber(value,xdecimal);
g.drawString(label,i-metrics.stringWidth(label)/2,height-yoff-yspace+metrics.getHeight()/2+6);
g.drawLine(i,height-yoff-yspace,i,height-yoff-yspace+5);
if(grid) {
g.setColor(gridcolor);
g.drawLine(i,height-yoff-yspace,i,yoff+TOP_ADD);
g.setColor(color);
}
j++;
if(j>xcount) break;
} // draw the y axis scale. "i" is pixel,DO NOT TREATE IT LIKE ARRAY-INDEX!
j = 0;
for(int i=height-yoff-yspace;i>=yoff+TOP_ADD;i=(int)Math.round((height-yoff-yspace)-j*(height-(yoff+yoff+TOP_ADD+yspace))*1.0/ycount)) {
value = ((height-yoff-yspace)-i)/((height-(yoff+yoff+TOP_ADD+yspace))/ycount)*(ymax/ycount);
// format display.
label = StringKit.formatNumber(value,ydecimal);
g.drawString(label,(xoff+XDIR_ADD+xspace)-metrics.stringWidth(label)-6,i+metrics.getAscent()/2);
g.drawLine((xoff+XDIR_ADD+xspace),i,(xoff+XDIR_ADD+xspace)-5,i);
if(grid) {
g.setColor(gridcolor);
g.drawLine((xoff+XDIR_ADD+xspace),i,width-(xoff+XDIR_ADD),i);
g.setColor(color);
}
j++;
if(j>xcount) break;
} // x/y label.
// font = new Font("宋体",Font.PLAIN,12);
// g.setFont(font);
// g.setStroke(new BasicStroke(2.0f));
// metrics = g.getFontMetrics(); g.drawString(xlabel,width/2-metrics.stringWidth(xlabel)/2,height-yoff-yspace+metrics.getHeight()/2+6+metrics.getHeight());
g.drawString(ylabel,(xoff+XDIR_ADD+xspace)-metrics.stringWidth(ylabel)/2,yoff+TOP_ADD-metrics.getHeight());
}
}