[英]Using Graphics object outside of the paint() method for a fractal java
I am trying to draw a fractal tree, and currently my design gleamed from other people's work is using graphics objects outside of the paint() method for recursion. 我正在尝试绘制一个分形树,目前我的设计从其他人的工作中闪闪发光,使用paint()方法之外的图形对象进行递归。 Will this result in anything at all?
这会导致什么吗?
您可以从BufferedImage获取Graphics对象(甚至是支持数组)并在其上绘制,然后在paintComponent()中绘制图像。
You need to pass the Graphics
context as a parameter to your drawMethod(Graphics g)
, then invoke than method withing the paint
method. 你需要通过
Graphics
上下文作为参数传递给您的drawMethod(Graphics g)
然后调用方法相比的withing paint
方法。 drawMethod(g);
, g
being the Graphics
context of the paint
method ,
g
是paint
方法的Graphics
上下文
public class SomeClass {
public void drawMethod(Graphics g) {
g.drawString("Hello World", 50, 50);
}
}
public class DrawPanel extends JPanel {
SomeClass someClass = new SomeClass();
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
someClass.drawMethod(g);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.