guanghezun
guanghezun
2019-11-15 01:38

请问关于JPanel 中paint 方法重写的问题,void is an invalid type for the variable paint

  • java
  • eclipse

import java.awt.Graphics;
import javax.swing.JPanel;

public class ipanel extends JPanel {

public ipanel () {
public void paint(Graphics g) {

g.drawLine(0, 0, 10, 10);
}
}
}

public class Test {
public static void main(String[] args) {
new ipanel();
}
}
编译会出现void is an invalid type for the variable paint的错误,即使在paint加入父类方法也没用。
可是在ipanel的构造器中应该是可以出现函数的吧?
请教大家,谢谢!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答