jsp页用Applet画线段问题?? 你是不会话那条线,还是不会再jsp里面调用???哥们。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我主要有三个大问题啊 1 不知道如何把jsp页面组织的数据(很多点piont1,piont2,piont3....)传到applet中。 2 不知道如何在applet中显示确定的横纵坐标(要求显示出坐标系) 3 不知道如何在applet中规定好的坐标中画由1传递的很多点之间的直线。大家帮帮忙啊?? 我考,这就是说,你没有一点会的地方啊。传递到applet好办了,用一个字符串就进去了。我晚上给你做一个,可能需要1个小时。 大家帮帮我。在jsp页中单击显示画图按钮,就把jsp中组织好的数据(若干个点piont1,piont2..)传递到APPLET中。则APPLET中是有横纵坐标,在这个坐标的基础上画一条曲线啊??? package com.zhang.paint;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class PaintCanvas extends JPanel { private int originX; private int originY; private int xScape = 10; private int yScape = 10; private double xDataScope; private double yDataScope; private double xMin; private double yMin; private Point[] xyData; private int chartWidth; private int chartHeight; public PaintCanvas(double xScope,double yScope,double xmin,double ymin ) { this.xDataScope = xScope; this.yDataScope = yScope; this.xMin = xmin; this.yMin = ymin; this.addComponentListener(new CanvasListener()); } public void paintComponent(Graphics g){ /** * draw the XYCoord * */ Graphics2D g2 = (Graphics2D)g; Color old = g2.getColor(); g2.setColor(Color.white); g2.fillRect(0,0,this.getWidth(),this.getHeight()); g2.setColor(Color.red); g.drawLine(this.originX,this.originY,this.originX+this.chartWidth,this.originY); //x轴 g.drawLine(this.originX,this.originY,this.originX,this.originY - this.chartHeight);//y for (int i=0;i<this.xyData.length;i++){ if (i>0){ Point pt1 = this.dataToCanvas(xyData[i-1]); Point pt2 = this.dataToCanvas(xyData[i]); int x = (int)pt1.getX(); int y = (int)pt1.getY(); int x1 = (int)pt2.getX(); int y1 = (int)pt2.getY(); g.drawLine(x, y, x1,y1); } } } public void setPoints(String pts){ String[] tmp = pts.split(";"); xyData = new Point[tmp.length]; for (int i=0;i<tmp.length;i++){ String[] t1 = tmp[i].split(","); int x = Integer.parseInt(t1[0]); int y = Integer.parseInt(t1[1]); Point pt = new Point(x,y); xyData[i] = pt; } repaint(); } private Point dataToCanvas(Point pt){ double x = (pt.getX()-this.xMin) * (this.chartWidth / this.xDataScope) + this.originX; double y = (this.originY - this.chartHeight) + (this.yMin+this.yDataScope - pt.getY()) * (this.chartHeight / this.yDataScope); Point ptR = new Point((int)x,(int)y); return ptR; } private void resized(){ chartWidth = getWidth() - xScape * 2; chartHeight = getHeight() - yScape * 2; originX = xScape; originY = getHeight() - yScape; repaint(); } private class CanvasListener extends ComponentAdapter{ public void componentResized(ComponentEvent e){ resized(); } } public static void main(String[] aa){ PaintCanvas pc = new PaintCanvas(500,1000,0,0); JFrame fr = new JFrame(); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fr.getContentPane().add("Center",pc); String pts = "0,0;300,600;400,800;300,50"; fr.show(); pc.setPoints(pts); }}给你弄了个例子哦,你只要潜入applet,然后呢,吧你的点数据弄成字符串,传递给setPoints就可以了。呵呵,其他地方你自己完善吧。这是我早上弄得个例子。 <applet code="Web_Paint.class" width="100%" height=500><param name="Background" value="white"><param name="Foreground" value="blue"><param name="IconNameList" value="图元构件1,图元构件2"><param name="IconURLList" value="Tomcat.gif,Tiger.gif"></applet>import java.awt.*;import java.awt.event.*;import java.applet.*;public class Web_Paint extends Applet{ int iHistoryX=0; int iHistoryY=0; int iPosX=0; int iPosY=0; int iWidth=0; int iHeight=0; int iTempX; int iTempY; int iR=0; int iType=0;//0:线;1:框;2:圆;3:文;4:件; String strImageURL; Image m_Com; LayoutManager DC_Layout; Choice m_Type; Choice m_Icon; TextField m_Info; String strInfo; String strIconName; String strIconURL; String[] IconNameArray; String[] IconURLArray; int iCurIcon=0; public void init() { setBackground(Color.white); setForeground(Color.blue); DC_Layout=new FlowLayout(FlowLayout.LEFT,10,5); setLayout(DC_Layout); m_Type=new Choice(); m_Type.addItem("线");m_Type.addItem("框");m_Type.addItem("圆");m_Type.addItem("文");m_Type.addItem("件"); add(m_Type); m_Info=new TextField("标注文本",30); add(m_Info); m_Icon=new Choice(); strIconName=getParameter("IconNameList"); strIconURL=getParameter("IconURLList"); IconNameArray=strIconName.split(","); IconURLArray=strIconURL.split(","); for(int iIndex=0;iIndex<IconNameArray.length;iIndex++) { m_Icon.addItem(IconNameArray[iIndex]); } add(m_Icon); } public void paint(Graphics g) { switch(iType) { case 0: g.drawLine(iTempX,iTempY,iPosX,iPosY); break; case 1: g.drawRect(iHistoryX,iHistoryY,iWidth,iHeight); break; case 2: g.drawArc(iTempX,iTempY,iR,iR,0,360); break; case 3: g.drawString(strInfo,iTempX,iTempY); break; case 4: if(m_Com!=null) { g.drawImage(m_Com,iTempX,iTempY,null); } break; default: g.drawRect(iHistoryX,iHistoryY,iWidth,iHeight); break; } } public boolean mouseDown(java.awt.Event event,int iX,int iY) { iHistoryX=iX; iHistoryY=iY; iTempX=iHistoryX; iTempY=iHistoryY; if(iType==3) { strInfo=m_Info.getText(); repaint(); } if(iType==4) { strImageURL=IconURLArray[iCurIcon]; m_Com=getImage(getCodeBase(),strImageURL); repaint(); } return true; } public boolean mouseDrag(java.awt.Event event,int iX,int iY) { iPosX=iX; iPosY=iY; iR=iX-iHistoryX; if(iR<0) { iR=iHistoryX-iX; repaint(); } else { repaint(); } iWidth=iX-iHistoryX; iHeight=iY-iHistoryY; if(iWidth<=0&&iHeight<=0) { iHistoryX=iX; iHistoryY=iY; iWidth=iTempX-iHistoryX; iHeight=iTempY-iHistoryY; repaint(); } else { repaint(); } return true; } public boolean action(Event e,Object arg) { if(e.target instanceof Choice) { if("线".equals(e.arg)) { iType=0; return true; } if("框".equals(e.arg)) { iType=1; return true; } if("圆".equals(e.arg)) { iType=2; return true; } if("文".equals(e.arg)) { iType=3; return true; } if("件".equals(e.arg)) { iType=4; return true; } String strIconName_; for(int kIndex=0;kIndex<IconNameArray.length;kIndex++) { strIconName_=IconNameArray[kIndex]; if(strIconName_.equals(e.arg)) { iCurIcon=kIndex; } } } return false; }} 网上书店 ext 如何能让combo的当前值显示的是从数据库中返回来的值呢? struts2 链接传参 取不到参数的值 如何在光标处显示表格中某条记录的相关信息? 请教一个JSP的问题?高手帮忙 不认添加重复的记录??在线等??? wap1.2问题?? 我要用java 的相关技术做心跳检测的客户端,和用户的上下线请请求,知道原理的请进 我怎么实现远程MYSQL数据库的快速读取? 初级问题! 大家帮帮忙! A求救啊!!applet.class文件如果存在一个package中,<applet>就是找不到? tomcat+sql server2000的连接池配置问题20分
1 不知道如何把jsp页面组织的数据(很多点piont1,piont2,piont3....)传到applet中。
2 不知道如何在applet中显示确定的横纵坐标(要求显示出坐标系)
3 不知道如何在applet中规定好的坐标中画由1传递的很多点之间的直线。大家帮帮忙啊??
大家帮帮我。在jsp页中单击显示画图按钮,就把jsp中组织好的数据(若干个点piont1,piont2..)传递到APPLET中。则APPLET中是有横纵坐标,在这个坐标的基础上画一条曲线啊???
import java.awt.*;
import java.awt.event.*;public class PaintCanvas extends JPanel {
private int originX;
private int originY; private int xScape = 10;
private int yScape = 10; private double xDataScope;
private double yDataScope; private double xMin;
private double yMin; private Point[] xyData; private int chartWidth;
private int chartHeight;
public PaintCanvas(double xScope,double yScope,double xmin,double ymin ) {
this.xDataScope = xScope;
this.yDataScope = yScope;
this.xMin = xmin;
this.yMin = ymin;
this.addComponentListener(new CanvasListener());
}
public void paintComponent(Graphics g){
/**
* draw the XYCoord
* */
Graphics2D g2 = (Graphics2D)g;
Color old = g2.getColor(); g2.setColor(Color.white);
g2.fillRect(0,0,this.getWidth(),this.getHeight()); g2.setColor(Color.red); g.drawLine(this.originX,this.originY,this.originX+this.chartWidth,this.originY); //x轴
g.drawLine(this.originX,this.originY,this.originX,this.originY - this.chartHeight);//y
for (int i=0;i<this.xyData.length;i++){
if (i>0){
Point pt1 = this.dataToCanvas(xyData[i-1]);
Point pt2 = this.dataToCanvas(xyData[i]);
int x = (int)pt1.getX();
int y = (int)pt1.getY();
int x1 = (int)pt2.getX();
int y1 = (int)pt2.getY();
g.drawLine(x, y, x1,y1);
}
} }
public void setPoints(String pts){
String[] tmp = pts.split(";");
xyData = new Point[tmp.length];
for (int i=0;i<tmp.length;i++){
String[] t1 = tmp[i].split(",");
int x = Integer.parseInt(t1[0]);
int y = Integer.parseInt(t1[1]);
Point pt = new Point(x,y);
xyData[i] = pt;
} repaint();
} private Point dataToCanvas(Point pt){
double x = (pt.getX()-this.xMin) * (this.chartWidth / this.xDataScope) + this.originX;
double y = (this.originY - this.chartHeight) + (this.yMin+this.yDataScope - pt.getY()) * (this.chartHeight / this.yDataScope);
Point ptR = new Point((int)x,(int)y);
return ptR;
}
private void resized(){
chartWidth = getWidth() - xScape * 2;
chartHeight = getHeight() - yScape * 2; originX = xScape;
originY = getHeight() - yScape; repaint();
} private class CanvasListener extends ComponentAdapter{
public void componentResized(ComponentEvent e){
resized();
}
} public static void main(String[] aa){
PaintCanvas pc = new PaintCanvas(500,1000,0,0);
JFrame fr = new JFrame();
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fr.getContentPane().add("Center",pc); String pts = "0,0;300,600;400,800;300,50"; fr.show(); pc.setPoints(pts);
}
}给你弄了个例子哦,你只要潜入applet,然后呢,吧你的点数据弄成字符串,传递给setPoints就可以了。呵呵,其他地方你自己完善吧。这是我早上弄得个例子。
<param name="Background" value="white">
<param name="Foreground" value="blue">
<param name="IconNameList" value="图元构件1,图元构件2">
<param name="IconURLList" value="Tomcat.gif,Tiger.gif">
</applet>
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Web_Paint extends Applet
{
int iHistoryX=0;
int iHistoryY=0;
int iPosX=0;
int iPosY=0;
int iWidth=0;
int iHeight=0;
int iTempX;
int iTempY;
int iR=0;
int iType=0;//0:线;1:框;2:圆;3:文;4:件;
String strImageURL;
Image m_Com;
LayoutManager DC_Layout;
Choice m_Type;
Choice m_Icon;
TextField m_Info;
String strInfo;
String strIconName;
String strIconURL;
String[] IconNameArray;
String[] IconURLArray;
int iCurIcon=0; public void init()
{
setBackground(Color.white);
setForeground(Color.blue);
DC_Layout=new FlowLayout(FlowLayout.LEFT,10,5);
setLayout(DC_Layout);
m_Type=new Choice();
m_Type.addItem("线");m_Type.addItem("框");m_Type.addItem("圆");m_Type.addItem("文");m_Type.addItem("件");
add(m_Type);
m_Info=new TextField("标注文本",30);
add(m_Info);
m_Icon=new Choice();
strIconName=getParameter("IconNameList");
strIconURL=getParameter("IconURLList");
IconNameArray=strIconName.split(",");
IconURLArray=strIconURL.split(",");
for(int iIndex=0;iIndex<IconNameArray.length;iIndex++)
{
m_Icon.addItem(IconNameArray[iIndex]);
}
add(m_Icon);
} public void paint(Graphics g)
{
switch(iType)
{
case 0:
g.drawLine(iTempX,iTempY,iPosX,iPosY);
break;
case 1:
g.drawRect(iHistoryX,iHistoryY,iWidth,iHeight);
break;
case 2:
g.drawArc(iTempX,iTempY,iR,iR,0,360);
break;
case 3:
g.drawString(strInfo,iTempX,iTempY);
break;
case 4:
if(m_Com!=null)
{
g.drawImage(m_Com,iTempX,iTempY,null);
}
break;
default:
g.drawRect(iHistoryX,iHistoryY,iWidth,iHeight);
break;
}
} public boolean mouseDown(java.awt.Event event,int iX,int iY)
{
iHistoryX=iX;
iHistoryY=iY;
iTempX=iHistoryX;
iTempY=iHistoryY;
if(iType==3)
{
strInfo=m_Info.getText();
repaint();
}
if(iType==4)
{
strImageURL=IconURLArray[iCurIcon];
m_Com=getImage(getCodeBase(),strImageURL);
repaint();
}
return true;
} public boolean mouseDrag(java.awt.Event event,int iX,int iY)
{
iPosX=iX;
iPosY=iY;
iR=iX-iHistoryX;
if(iR<0)
{
iR=iHistoryX-iX;
repaint();
}
else
{
repaint();
}
iWidth=iX-iHistoryX;
iHeight=iY-iHistoryY;
if(iWidth<=0&&iHeight<=0)
{
iHistoryX=iX;
iHistoryY=iY;
iWidth=iTempX-iHistoryX;
iHeight=iTempY-iHistoryY;
repaint();
}
else
{
repaint();
}
return true;
} public boolean action(Event e,Object arg)
{
if(e.target instanceof Choice)
{
if("线".equals(e.arg))
{
iType=0;
return true;
}
if("框".equals(e.arg))
{
iType=1;
return true;
}
if("圆".equals(e.arg))
{
iType=2;
return true;
}
if("文".equals(e.arg))
{
iType=3;
return true;
}
if("件".equals(e.arg))
{
iType=4;
return true;
}
String strIconName_;
for(int kIndex=0;kIndex<IconNameArray.length;kIndex++)
{
strIconName_=IconNameArray[kIndex];
if(strIconName_.equals(e.arg))
{
iCurIcon=kIndex;
}
}
}
return false;
}
}