| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 862 人关注过本帖
标题:在jsp页面里动态生成图形,用java来写bean可不可行?
只看楼主 加入收藏
sowing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-5-22
收藏
 问题点数:0 回复次数:8 
在jsp页面里动态生成图形,用java来写bean可不可行?

项目要用jsp作网页,里面要用鼠标选定区域动态生成图。
现在用的是java编一个bean来实现的。对java也是不怎么懂,边摸边画。
不知道,下面这个可不可行。请各位大虾帮我看看哦。

package mouse;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.image.*;
import java.applet.*;


/*为了达到画线的功能,我们分别implements MouseListener与MouseMotionListener.
*/
public class mouseBean extends JFrame implements MouseListener,MouseMotionListener{

String str;
BufferedImage image;
Image rect;
int flag;
int x=0;
int y=0;
int startx,starty,endx,endy;//起始坐标与终点坐标
int imgOrig = 50000000;
int zoomLength = imgOrig;
int imgStart = 0;
int imgEnd = imgStart + zoomLength;

public mouseBean(){
Container contentPane=getContentPane();
contentPane.addMouseListener(this);
contentPane.addMouseMotionListener(this);
setSize(1000,1000);

setVisible(true);
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}
public void drawCoordinate(Graphics g) //draw coordinate
{
int interval = zoomLength>>2;
for(int i=imgStart; i<imgEnd; i+=interval)
{
g.drawLine(((int)(i-imgStart)/zoomLength*800),130,((int)(i-imgStart)/zoomLength*800),135);
if(i>1000000)
{
int j=i/1000000;
g.drawString(String.valueOf(j)+"M",((int)(i-imgStart)/zoomLength*800),133);
}
else if((i>1000)&&(i<1000000))
{
int j=i/1000;
g.drawString(String.valueOf(j)+"K",((int)(i-imgStart)/zoomLength*800),133);
}
else
g.drawString(String.valueOf(i),((int)(i-imgStart)/zoomLength*800),133);
}
}
/*由mousePressed(),mouseReleased()取得示拖曳的开始与结束坐标*/
public void mousePressed(MouseEvent e){
startx=e.getX();
starty=e.getY();
}

public void mouseReleased(MouseEvent e){
endx=e.getX();
endy=e.getY();

Container c=(Container)e.getSource();
Graphics g=c.getGraphics();

//Graphics g = null;
int zoom;
int zoomTemp;

if(endx > startx){
zoomTemp = (endx-startx)/800*zoomLength;
imgStart = imgStart + ((startx - /*imgleftx*/100)/800*zoomLength);
//imgEnd = imgStart + zoomLength;
zoomLength = zoomTemp;
zoom = imgOrig/zoomLength;
if(zoom <= 30){
flag = 1;
paint(g);
}
if((zoom>30)&&(zoom<=900)){
flag = 2;
paint(g);
}
if((zoom>900)&&(zoom<=27000)){
flag = 3;
paint(g);
}
if((zoom>27000)&&(zoom<=810000)){
flag = 4;
paint(g);
}
}
else{
int exchange = startx;
startx = endx;
endx = exchange;

zoomTemp = 800/(endx-startx)*zoomLength;
zoomLength = zoomTemp;
zoom = imgOrig/zoomLength;

if(zoomTemp>imgOrig)
{
zoomLength = imgOrig;
imgStart = 0;
imgEnd = imgStart + zoomLength;
}
if(zoom<=30){
flag = 1;
paint(g);
}
if((zoom>30)&&(zoom<=900)){
flag = 2;
paint(g);
}
if((zoom>900)&&(zoom<=27000)){
flag = 3;
paint(g);
}
if((zoom>27000)&&(zoom<=810000)){
flag = 4;
paint(g);
}

imgStart = imgStart + (zoomLength>>1) - (int)(zoomTemp%2.0); //zoom out in center
}
}


public void mouseEntered(MouseEvent e){ }
public void mouseExited(MouseEvent e){ }
public void mouseClicked(MouseEvent e){ }
/*mouseMoved(),mouseDragged()取得鼠标移动的每一个坐标,并调用repaint()方法*/
public void mouseMoved(MouseEvent e){
//flag=1;
x=e.getX();
y=e.getY();
repaint();
}

public void mouseDragged(MouseEvent e){
//flag=2;
//x=e.getX();
//y=e.getY();
//repaint();
}

public void update(Graphics g){
g.setColor(this.getBackground());
g.fillRect(100,100,/*getWidth()*/800,/*getHeight()*/500);
paint(g);
}

public void paint(Graphics g){
int geneWidth;
int geneNum;
int queryNum;
String sbuf;
if(flag==1)
{
g.setColor(Color.blue);
g.fillRect(100,150,/*getWidth*/800,/*getHeight*/500);

geneNum = findGenes(imgStart,imgEnd).length; //find genes from whole_genes.txt and no mark symbol
gene[] gn = new gene[geneNum];
for(int i=0; i<geneNum; i++)
{
geneWidth = gn[i].txEnd - gn[i].txStart;
g.fillRect((int)(800/zoomLength*(gn[i].txStart-imgStart)),150,((int
geneWidth/zoomLength*800),20); //show every gene in this region
}
}
if(flag == 2)
{

g.setColor(Color.blue);
g.drawLine(100,150,/*getWidth*/800,150);

geneNum = findGenes(imgStart,imgEnd).length;
gene[] gn = new gene[geneNum];
for(int i=0; i<geneNum; i++)
{
geneWidth = gn[i].txEnd - gn[i].txStart;
g.fillRect((int)(/*getWidth*/800/zoomLength*(gn[i].txStart-imgStart)),140,((int)geneWidth/zoomLength*/*getWidth*/800),20); //show genes & mark genes' name
g.drawString("gn[geneNum].symbol",(int)(/*getWidth*/800/zoomLength*(gn[i].txStart-imgStart)),135);
}
}
if(flag == 3)
{
g.setColor(Color.blue);
g.drawLine(100,150,/*getWidth*/800,150);

geneNum = findGenes(imgStart,imgEnd).length;
gene[] gn = new gene[geneNum];
for(int i=0; i<geneNum; i++)
{
geneWidth = gn[i].txEnd - gn[i].txStart;
g.fillRect((int)(800/zoomLength*(gn[i].txStart-imgStart)),140,((int)(geneWidth/zoomLength*800)),20); //show genes
g.drawString("gn[geneNum].symbol",(int)(800/zoomLength*(gn[i].txStart-imgStart)),135); //mark genes' name

for(int j=0; j<gn[geneNum].exonCount; j++) //show exons
{
int exonLen = gn[i].exonEnds[j] - gn[i].exonStarts[j];
int exonWidth = exonLen/zoomLength*800;
g.fillRect((int)(800/zoomLength*(gn[i].exonStarts[j]-imgStart)),140,exonWidth,20);
}
}

queryNum = findQueries(imgStart,imgEnd).length;
query[] qr = new query[queryNum];
for(int j=0; j<queryNum; j++) //show queries & mark queries' position
{
int qrLen = qr[j].qrEnd - qr[j].qrStart;
int qrWidth = qrLen/zoomLength*/*getWidth*/800;
g.setColor(Color.red);
g.drawLine((int)(/*getWidth*/800/zoomLength*(qr[j].qrStart-imgStart)),170,(int)(/*getWidth*/800/zoomLength*(qr[j].qrStart-imgStart))+ qrWidth,170);
}

}
if(flag == 4) //show their sequences
{
g.setColor(Color.blue);
char cbuf[] = new char[1000];
sbuf = getGeneSeq(imgStart,imgEnd);
g.drawString(sbuf,100,150);

g.setColor(Color.red);
queryNum = findQueries(imgStart,imgEnd).length;
query[] qr = new query[queryNum];
for(int i=0; i<queryNum; i++)
{
g.drawString(qr[i].seq,(int)(800/zoomLength*(qr[i].qrStart-imgStart)),170); //how to decide its position? is it right?
}

}
}
public gene[] findGenes(int x,int y)
{
try{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\blast\\blast数据库\\genes_chr22.txt")));
String geneline = null;
String[] geneTemp = geneline.split(" ");

int Start = Integer.parseInt(geneTemp[2]);
int End = Integer.parseInt(geneTemp[3]);

gene[] gn = new gene[100];
for(int m=0; m<100; m++)
{
gn[m] = new gene();
}

int geneNum = 0;
while((geneline = br.readLine())!= null)
{
geneTemp = geneline.split(" ");
if((Start>x)&&(End<y))
{
geneNum++;
gn[geneNum].txStart = Integer.parseInt(geneTemp[2]);
gn[geneNum].txEnd = Integer.parseInt(geneTemp[3]);
gn[geneNum].symbol = geneTemp[5];
gn[geneNum].exonCount = Integer.parseInt(geneTemp[6]);

for(int i=0; i<gn[geneNum].exonCount; i++)
{
gn[geneNum].exonStarts[i] = Integer.parseInt(geneTemp[6+i*2-1]);
gn[geneNum].exonEnds[i] = Integer.parseInt(geneTemp[6+i*2]);
}
}
geneline = br.readLine();
}
return gn;
}catch(IOException e){
System.out.println(e.getStackTrace());
return null;
}
}

public query[] findQueries(int x,int y)
{
try{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\blast\\blast数据库\\query_chr22.txt")));
String queryline = null;
String[] queryTemp = queryline.split(" ");
int Start = Integer.parseInt(queryTemp[2]);
int End = Integer.parseInt(queryTemp[3]);

query[] qr = new query[100];
for(int n=0; n<100; n++)
{
qr[n] = new query();
}

int queryNum = 0;
while((queryline = br.readLine())!= null)
{
queryTemp = queryline.split(" ");
if((Start > x)&&(End < y))
{
queryNum++;
qr[queryNum].queryIndex = Integer.parseInt(queryTemp[0]);
qr[queryNum].qrStart = Integer.parseInt(queryTemp[2]);
qr[queryNum].qrEnd = Integer.parseInt(queryTemp[3]);
qr[queryNum].seq = queryTemp[4];
qr[queryNum].varNum = Integer.parseInt(queryTemp[5]);

for(int i=0; i<qr[queryNum].varNum; i++)
{
qr[queryNum].varPos[i]= Integer.parseInt(queryTemp[6+i]);
}
}
queryline = br.readLine();
}
return qr;
}
catch(IOException e){
System.out.println(e.getStackTrace());
return null;
}
}

public String getGeneSeq(int x,int y) //read gene sequences
{
try{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\blast\\blast数据库\\seq_"+str+".txt")));
int off = x;
int len = y - x;
char cbuf[] = new char[len];
//String sbuf = cbuf.toString();
br.read(cbuf,off,len);
String sbuf = cbuf.toString();
return sbuf;
}
catch(IOException e){
System.out.println(e.getStackTrace());
return null;
}
}

}


class gene
{
public int txStart;
public int txEnd;
public String symbol;
public int exonCount;
public int exonStarts[];
public int exonEnds[];

}

class query
{
public int queryIndex;
public int qrStart;
public int qrEnd;
public String seq;
public int varNum;
public int varPos[];
public String varInf;
}

搜索更多相关主题的帖子: bean java 图形 jsp 动态 
2007-05-29 15:15
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 
这种东西可以实现在网页上画图???

老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-05-29 15:26
sowing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-5-22
收藏
得分:0 
??如果写成bean也不可以吗?
2007-05-29 16:35
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 

不清楚,我觉得好像不行,行的话你告诉我!!


老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-05-29 16:38
sowing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-5-22
收藏
得分:0 

呵呵。。晕。你是版主呢。
那要实现在jsp里,用鼠标选定区域动态生成图形,一般都用什么方法实现?

2007-05-29 16:54
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 
你是要做电子地图那样的东西么?

1.基于CGI/ISAPI的服务器模式
2.基于Java或Java Applet的客户机服务器两端编程的模式
3.通过下载ActiveX控件到客户机上解释数据的方式和插件(Plug-in)方式。

老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-05-29 17:11
sowing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-5-22
收藏
得分:0 
差不多。
就是选定的区域越小,想显示的东西越多越清楚。
1,3压根儿不懂。那是不是就用applet好些?
如果不用applet,用JComponent然后override paintComponent()
这两种方法哪个更好一些?
2007-05-29 17:17
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 
如果在网页中我想APPLET吧!
这东西我是没弄过,WEBGIS这类东西很麻烦的!

老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-05-29 17:24
sowing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-5-22
收藏
得分:0 

哦,那还是applet吧。谢谢斑竹:)

2007-05-29 17:27
快速回复:在jsp页面里动态生成图形,用java来写bean可不可行?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047802 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved