⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 series.java

📁 用于显示适时的曲线图
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;
import java.util.*;
class SeriesValue
{
	int ID = 0;
	float y = 0 ;
	float x = 0;
	String TextY = new String("");
	String TextX = new String("");
	boolean Use = false;
	SeriesValue()
	{
	}
	SeriesValue(int ID, float x, float y, boolean Use)
	{
		this.ID = ID;
		this.x = x;
		this.y = y;
		this.Use = Use;
	}
};

class Series extends Object
{
	Vector Value = new Vector();
	private Point Origin = new Point(0,0);
	boolean IsVisible = true;

	int Type =0; //0 - continued line 
		
	Color color = Color.black;

	private float MapY = 1;
	private float MapX = 1;

	private float MaxX = 100;
	private float MaxY = 100;
	private float MinX = 0;
	private float MinY = 0;

	String Title = new String("");

	void setColor(Color c)
	{
		color = c;
	}
	void setMap(float x, float y)
	{
		MapX = x; MapY = y;
	}
	void setMaxMinY(float max, float min)
	{
		MaxY =  max>min?max:min; MinY =  max<min?max:min;
	}
	float getMaxY()
	{
		return MaxY;
	}
	float getMaxX()
	{
		return MaxX;
	}
	float getMinY()
	{
		return MinY;
	}
	float getMinX()
	{
		return MinX;
	}
	float getMapX()
	{
		return MapX;
	}
	float getMapY()
	{
		return MaxY;
	}
	void setMaxMinX(float max, float min)
	{
		MaxX =  max>min?max:min; MinX =  max<min?max:min;
	}
	void setOrigin(Point O)
	{
		Origin = O;
	}
	void  addValue(float x,float y)
	{
		Value.addElement(new SeriesValue(Value.size(), x, y, true));
	}
	void  addValue(float x,float y,String s)
	{
		SeriesValue t = new SeriesValue(Value.size(), x, y, true);
		t.TextX = s;
		Value.addElement(t);
	}
	void  addValue(float x,float y,String Xs,String Ys)
	{
		SeriesValue t = new SeriesValue(Value.size(), x, y, true);
		t.TextX = Xs; t.TextY = Ys;
		Value.addElement(t);
	}
	void setTitle(String s)
	{
		Title = s;
	}
	String getTitle()
	{
		return Title;
	}
	void draw(Graphics g)
	{
		int i;
		if(Value.size()<=0)
			return;
		int x  ;
		int y  ;
		Vector xy = new Vector();
		g.setColor(color);
		float tx;
		float ty;
		boolean tb;
//		System.out.println("mapx,y:"+MapX+","+MapY+" x,y:"+MinX+","+MinY);
		for(i=0 ; i<Value.size(); i++)
		{
			ty = ((SeriesValue)Value.elementAt(i)).y;
			tx = ((SeriesValue)Value.elementAt(i)).x;
			tb = ((SeriesValue)Value.elementAt(i)).Use;
		//	System.out.println(ty);
			if(tx<MinX || tx>MaxX || !tb)
				continue;
			y = Origin.y - Math.round( (ty - MinY)/MapY );
			x = Origin.x + Math.round( (tx - MinX)/MapX );
			xy.addElement(new Point(x, y));
		}
		g.setColor(color);
		for(i=0; i<xy.size()-1; i++)
		{
			g.drawLine(((Point)xy.elementAt(i)).x, ((Point)xy.elementAt(i)).y, 
				((Point)xy.elementAt(i+1)).x, ((Point)xy.elementAt(i+1)).y);
		}
	}
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -