stockmonitor.java

来自「用于串口通讯测试的工具软件。完全使用java语言编写。」· Java 代码 · 共 97 行

JAVA
97
字号
package com.zcsoft.stock;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.Timer;
import com.zcsoft.stock.Device;
import com.zcsoft.graphics.line.ShapePane;
import java.awt.image.BufferedImage;

/**
 * <p>Title: 串口通信</p>
 * <p>Description: 串口通信实验</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: Zhicheng Software&Service Co. Ltd.</p>
 * @author 蒋智湘
 * @version 1.0
 */

public class StockMonitor extends ShapePane
{
	/** 监视的所有设备 */
	DeviceMaker[] devices;
	/** 背景图片 */
	BufferedImage backGround;
	//private float scaleX = 1F, scaleY = 1F;

	public StockMonitor(Image backGround)
	{
		this.setBackground(backGround);
		//this.removeMouseListener(this);
		//this.removeMouseMotionListener(this);
		//this.setDoubleBuffered(true);
	}

	/**
	 * 设定背景图片
	 * @param backGround
	 */
	public void setBackground(Image backGround)
	{
		if (backGround != null)
		{
			if (backGround instanceof BufferedImage)
			{
				this.backGround =  (BufferedImage)backGround;
			}
			else
			{
				this.backGround = new BufferedImage(backGround.getWidth(this)
																	, backGround.getHeight(this)
																	, BufferedImage.TYPE_INT_ARGB);
				Graphics g = this.backGround.getGraphics();
				g.drawImage(backGround, 0, 0, null);
				g.dispose();
			}

			this.setPreferredSize(new Dimension(this.backGround.getWidth(), this.backGround.getHeight()));
		}
	}

	/**
	 * 重写超类方法,使得背景可以绘制图片
	 * @param g
	 */
	public void paintChildren(Graphics g)
	{
		//super.paintChildren(g);
		if (this.backGround != null)
		{
			Rectangle clip = g.getClipBounds();
			g.drawImage(this.backGround.getSubimage(clip.x, clip.y, clip.width, clip.height), clip.x, clip.y, null);
		}
	}


	public DeviceMaker[] getDevices()
	{
		return (DeviceMaker[])devices;
	}

	/**
	 * 设定被监视的设备,同时重新启动刷新线程
	 * @param devices
	 */
	public void setDevices(DeviceMaker[] devices)
	{
		this.removeAllShapeMakers();
		for (int i = 0; i < devices.length; i++)
		{
			this.addShapeMaker(devices[i]);
		}
		this.devices = devices;
	}
}

⌨️ 快捷键说明

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