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

📄 visualbar.java

📁 赛车程序:先对赛道和赛车建立模型
💻 JAVA
字号:
/**
 * 
 */
package cn.tsinghua.ag5.CarModel;

import java.awt.*;
import java.awt.event.*;

import javax.swing.JPanel;

/**
 * @author wfq
 *
 */
public class VisualBar extends JPanel 
{
	private String m_log;
	double m_length;
	double m_max;
	
	public VisualBar(String p_log, double p_length, double p_max)
	{
		m_log = p_log;
		m_length = p_length;
		m_max = p_max;

		this.setBackground(Color.LIGHT_GRAY);
//		this.setSize(200, 80);
		this.setPreferredSize(new Dimension(200, 50));
	}
	
	public void paint( Graphics p_g)
	{
		super.paint(p_g);
		
		p_g.setFont(new Font("Monospaced", Font.PLAIN, 14));
		p_g.drawString(m_log, 10, 25);
		
		if(m_length <= 0)
		{
			p_g.setColor(Color.green);
			p_g.fill3DRect(60, 10, 5, 30, true);
		}else
		{
			p_g.setColor(Color.red);
			p_g.fill3DRect(60, 10, (int)Math.round(m_length / m_max * 130), 30, true);
		}
	}

	/**
	 * @return the length
	 */
	public double getLength() {
		return this.m_length;
	}

	/**
	 * @param p_length the length to set
	 */
	public void setLength(double p_length) {
		this.m_length = p_length;
	}

}

⌨️ 快捷键说明

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