java 提取曲线图数值并导出excel

来源:互联网 发布:剑网三网络助手 编辑:程序博客网 时间:2024/06/06 09:25


由于公路隧道通风辅助设计及网络分析系统中需要经常添加风机曲线,用Autocad取点或者Origin中的取点都不是很方便,所以采用Jpanel绘图取点的方式。

先上图:

点图取点及绘制点的部分代码:

jpgPan.addMouseListener(new MouseAdapter() {@Overridepublic void mousePressed(MouseEvent e) {if (e.getButton() == MouseEvent.BUTTON2) {isDragable = true;initx = e.getX();inity = e.getY();System.out.println("initx" + initx + "...." + "inity" + inity);jpgPan.setCursor(new Cursor(Cursor.HAND_CURSOR));}}@Overridepublic void mouseReleased(MouseEvent e) {jpgPan.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));isDragable = false;}@Overridepublic void mouseClicked(MouseEvent e) {if ((e.getClickCount() == 2) && isEnable) {num++;Graphics g = jpgPan.getGraphics();Color c = g.getColor();g.setColor(Color.RED);int x = e.getX();int y = e.getY();g.drawLine(x - 14, y, x + 14, y);g.drawLine(x, y - 14, x, y + 14);g.drawOval(x - 3, y - 3, 6, 6);g.drawOval(x - 8, y - 8, 16, 16);System.out.println(x + "----" + y);if (num == 1) {p0x = x;p0y = y;setStatusStr("坐标交点:   x=" + p0x + ", y=" + p0y);}if (num == 2) {pqx = x;pqy = y;setStatusStr("最大风量点:   x=" + pqx + ", y=" + pqy);}if (num == 3) {phx = x;phy = y;setStatusStr("最大风压点:   x=" + phx + ", y=" + phy);qcof = (pqx - p0x) / (qmax - q0);hcof = (phy - p0y) / (hmax - h0);}if (num > 3) {double q = (x - p0x) / qcof + q0;double h = (y - p0y) / hcof + h0;System.out.println("q=" + q + "h=" + h + "p0x=" + p0x + "p0y" + p0y + "qcof" + qcof + "hcof" + hcof);data[num - 4][0] = num - 3 + "";data[num - 4][1] = dfdouble1.format(q);data[num - 4][2] = dfdouble1.format(h);qhtablemodel.setDataVector(data, columnNames);qhtable.repaint();setStatusStr("曲线取点:   x=" + x + ", y=" + y);}g.setColor(c);g = null;}}});jpgPan.addMouseMotionListener(new MouseMotionAdapter() {@Overridepublic void mouseDragged(MouseEvent e) {if (isDragable) {double dx = e.getX() - initx;double dy = e.getY() - inity;double nx = sPane.getHorizontalScrollBar().getValue();double ny = sPane.getVerticalScrollBar().getValue();int newx = (int) (nx - dx);int newy = (int) (ny - dy);System.out.println(newx + "--????--" + newy);sPane.getHorizontalScrollBar().setValue(newx);sPane.getVerticalScrollBar().setValue(newy);}}});


0 0
原创粉丝点击