📄 show_1.java~1~
字号:
package curve;import java.awt.*;import javax.swing.JFrame;import java.util.*;import java.awt.event.*;public class Show_1 extends Canvas { Image bufferImage; // 缓冲图像 Graphics bufferGC; // 图形设备环境 curve c; // 曲线对象 int graphWidth; // 图形区域的宽度 int graphHeight; // 图形区域的高度 Vector v; // 统计数据矢量 Dimension d = new Dimension(500,400); // 绘制图像的内容 public void paint(Graphics g){ graphHeight=d.height-50; graphWidth =d.width-60; bufferImage=createImage(graphWidth,graphHeight); // 创建图形的绘制环境 bufferGC=bufferImage.getGraphics(); c=new curve(bufferGC); // 与绘制环境相关的曲线对象 //paintCurve("t","title"); c.drawAxes(graphWidth,graphHeight); c.makeHashMarks(5,56); g.drawImage(bufferImage,20,5,this); g.drawString("nihao",10,30); } // 使用Curve的方法--画曲线 public void paintCurve(String name,String title){ Vector actionVector=new Vector(); String actionString=new String(); actionVector=readData(name); actionString=readStringData(title); int xCount=actionVector.size(); int ytop=c.getTopY(actionVector); c.clearHashMarks(); c.clearScreen(); c.getMaxY(actionVector); c.drawAxes(graphWidth,graphHeight); c.makeHashMarks(xCount-1,ytop); // x轴刻度数 c.showData(actionVector); c.makeTitle(actionString); repaint(); } // 读取HTML数据参数到一个矢量对象,s代表程序控制的字符串(用于获取 HTML 的字符串)。 public Vector readData(String name){ Vector tempVector=new Vector(); Float param; String tempData=null; boolean datapresent=true; int i=0; while(datapresent){ try{ //tempData=getParameter(name+Integer.toString(i+1)); }catch(Exception e){ System.out.println(e); } if (tempData==null){ datapresent=false; }else{ param=Float.valueOf(tempData); tempVector.addElement(param); i+=1; } } return tempVector; } // 读取HTML字符串数据(包含相关数据的简要描述) public String readStringData(String title){ String tempString = null; try{ //tempString=getParameter(title); }catch(Exception e){ System.out.println(e); } return tempString; } public static void main(String[] args) { Show_1 show = new Show_1(); Frame f=new Frame("testing curve"); //c.addKeyListener(c); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){System.exit(0);} }); f.setLayout(new BorderLayout()); f.add(show,"Center"); f.setSize(500,400); f.setVisible(true); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -