67,513
社区成员
发帖
与我相关
我的任务
分享
public void paintComponent( Graphics g )
{
//先保证组件绘制正常
//指定图片载入
//才载入图片
if( loadImage != null )
{
if( loadneed )
super.paintComponent( g );
int height = this.getHeight();
int width = this.getWidth();
int imageHeight = loadImage.getHeight( null );
int imageWidth = loadImage.getWidth( null );
//优先以固定宽度的方式
//等比例显示图片
//绘图的坐标是窗口当前的位置开始
if( ( imageHeight * width/ imageWidth ) < height )
{
g.drawImage( loadImage, this.getLocation().x, this.getLocation().y,
width, imageHeight * width / imageWidth, null );
}
else
{
g.drawImage( loadImage, this.getLocation().x, this.getLocation().y,
height * imageWidth / imageHeight, height, null );
}
loadneed = false;
imageLoad = true;
}//end if loadImage
if( imageLoad && drawLine )
{
Graphics2D g2d = (Graphics2D) g;
g2d.setColor( paintColor );
g2d.drawPolyline(m_polygon.xpoints, m_polygon.ypoints, m_polygon.npoints);
}
}//end paintComponent