?? visualbar.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 + -