messagegraphic.java

来自「The ONE is a Opportunistic Network Envir」· Java 代码 · 共 44 行

JAVA
44
字号
/*  * Copyright 2008 TKK/ComNet * Released under GPLv3. See LICENSE.txt for details.  */package gui.playfield;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;

import core.*;

/**
 * Visualization of a message
 *
 */
public class MessageGraphic extends PlayFieldGraphic {
	private Color msgColor = Color.RED;
	
	private DTNHost from;
	private DTNHost to;
	
	public MessageGraphic(DTNHost from, DTNHost to) {
		this.to = to;
		this.from = from;
	}
	
	@Override
	public void draw(Graphics2D g2) {
		g2.setColor(msgColor);
		
		int fromX = scale(from.getLocation().getX());
		int fromY = scale(from.getLocation().getY());
		int toX = scale(to.getLocation().getX());
		int toY = scale(to.getLocation().getY());

		// line from "from host" to "to host"
		Polygon p = new Polygon(new int[] {fromX, toX}, 
				new int[] {fromY,toY}, 2);
		
		g2.draw(p);
	}
}

⌨️ 快捷键说明

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