Java - Calling paint method from different class?

霸气de小男生 提交于 2019-11-29 12:50:47

If I understand your question you could pass the Die instance into the Game constructor with something like

public class Game extends Frame {
  private Die die;
  public Game(Die die) {
    this.die = die;
  }
  public void window() {    
    setTitle("Roll");   //  Title of the window
    setLocation(100, 100);          //  Location of the window
    setSize(900, 600);              //  Size of the window
    setBackground(Color.lightGray); //  Color of the window
    setVisible(true);               //  Make it appear and call paint
    die.setVisible(true);           //  The same
  }
}

Then, wherever you call new Game() you add the Die instance argument. This is a fairly common way to implement a callback in Java (and other OOP languages).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!