如何使用图形作为参数调用空白

问题描述 投票:0回答:1
public void Filler(Graphics g) {
    super.paintComponent(g);
    g.setColor(Color.black);
    g.drawRect(Height, Width, 12, 12);
}

我如何称呼Filler void,因为显然它不想让我只做Filler();吗?

java
1个回答
0
投票

让我们看看您要调用的方法

public void Filler(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);
        g.drawRect(Height, Width, 12, 12);

}

注意在哪里显示(Graphics g)?这些被称为参数,这基本上意味着您要调用requires的方法将其传递给该参数的值。

在这种情况下,要调用您的方法,必须将其传递给Graphics对象。

所以您会这样称呼它:

Graphics g = new Graphics(); // creating this object also might require arguments to be passed!!
filler(g);

您不能只做filler();因为这意味着您没有传递任何值。

© www.soinside.com 2019 - 2024. All rights reserved.