Java 如何重写代码,使方法不会';不需要参数?
当前存在为ball类的paint方法调用display()的问题,但如果不提供Graphics2D g等参数,我将无法调用它。有什么建议吗Java 如何重写代码,使方法不会';不需要参数?,java,swing,awt,paintcomponent,Java,Swing,Awt,Paintcomponent,当前存在为ball类的paint方法调用display()的问题,但如果不提供Graphics2D g等参数,我将无法调用它。有什么建议吗 public class Main extends JPanel { Ball b; Graphics2D graph; public static void main(String[] args) throws InterruptedException { int xRange = 1000; int yRange = 1000;
public class Main extends JPanel {
Ball b;
Graphics2D graph;
public static void main(String[] args) throws InterruptedException {
int xRange = 1000;
int yRange = 1000;
//creates window
JFrame f = new JFrame("Tahmaseeb");
Ball b = new Ball();
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
while(true){
b.move();
b.display();
}
} }
其他球类
/**
* Painting the object
*/
void display(Graphics2D g) {
g.fillOval(this.posX, this.posY, 20, 20);
}
从阅读开始,更好地理解绘画是如何在摇摆中工作的,以及你应该如何与之结合。然后,阅读,更好地理解为什么你目前的方法是危险的和不值得推荐的,然后阅读,找到一个开始解决这个问题的地方