使用Java的图形为一个小程序时,你可以提高生产线的厚度?我不相信的BasicStroke工作 [英] Can you increase line thickness when using Java Graphics for an applet? I don't believe that BasicStroke works

查看:179
本文介绍了使用Java的图形为一个小程序时,你可以提高生产线的厚度?我不相信的BasicStroke工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦调整线条粗细。我可以这样做,在图形或做我必须做的Graphics2D的?如果是这样,我怎么修改程序,使其运行?

谢谢!

 进口java.applet.Applet中;
进口java.awt中的*。公共类myAppletNumberOne扩展的Applet {
    公共无效漆(图形页){
        //这里的东西?
    }
}


解决方案

是的,你必须这样做在的Graphics2D,但几乎没有一个问题,因为在Swing中的每个图形是一个Graphics2D对象(它只是让老接口的兼容性原因)。

 公共无效的paintComponent(图形G){    super.paintComponent方法(G);
    Graphics2D的G2 =(Graphics2D的)克;
    g2.setStroke(新的BasicStroke(3));
    g2.drawLine(...); //厚
    ...}

正如你所看到的,g2.setStroke(...)允许您更改行程,甚至有一个的BasicStroke它提供简单线条宽度选择。

I am having trouble adjusting line thickness. Can I do that in Graphics or do i have to do it in Graphics2D? If so, how do I alter the program to make it run?

Thanks!

import java.applet.Applet;
import java.awt.*;

public class myAppletNumberOne extends Applet {
    public void paint (Graphics page) {
        //Something here???
    }
}

解决方案

Yes you have to do it in Graphics2D, but that's hardly an issue, as every Graphics in Swing is a Graphics2D object (it just keeps the old interface for compatibility reasons).

public void paintComponent(Graphics g) {

    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(3));
    g2.drawLine(...);   //thick
    ...

}

As you can see, the g2.setStroke(...) allows you to change the stroke, and there's even a BasicStroke which provides for easy line width selection.

这篇关于使用Java的图形为一个小程序时,你可以提高生产线的厚度?我不相信的BasicStroke工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆