如何从对象调用覆盖方法

时间:2018-06-05 02:03:36

标签: java methods

如何调用paintComponent方法?

作为我大学课程的练习,我必须稍后在我的代码中调用paintComponent方法(在创建对象之后)。

任何提示?对不起我的noobness,我还在学习;)

    public class testPanel extends JPanel {

private testModel testModelHandle;
private Color[] colors;

public testPanel(testModel testModel) {
    if (testModel == null)
        throw new IllegalArgumentException("Should provide a valid instance of testModel!");
    this.testModelHandle = testModel;
    initializeColors();
}

private void initializeColors() {
    // Some tile colours in the '0xRRGGBB' format
    String[] testColorCodes = new String[]{
            "0x89CFF0", "0xF4C2C2", "0xFFBF00", "0xFBCEB1",
            "0x6495ED", "0x9BDDFF", "0xFBEC5D", "0xFF7F50",
            "0x00FFFF", "0x98777B", "0x99BADD", "0x654321"
    };
    colors = new Color[testColorCodes.length];
    for (int i = 0; i < colors.length; ++i)
        colors[i] = Color.decode(testColorCodes[i]);
}

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    //other stuff
}

}

0 个答案:

没有答案