java - Calling a method in main class from non main class -


i have 2 java classes:

boardmanager & board

boardmanager main class. inside contains board:

    public boardmanager(){         board b = new board();     }      public methodtobecalled(){}      public static void main(string[] args) {         new boardmanager();     } 

board user interface. when user presses button on interface want call method in boardmanager class, presents problem , unsure how around it.

one solution move main method board , this:

boardmanager boardmanager;      public board(){}      public void buttonpressed(){         boardmanager.methodtocall();     }      public static void main(string[] args) {         boardmanager = new boardmanager();     } 

but throw errors static , unstatic etc.

solutions? thanks!

either this:

class board{ static boardmanager boardmanager;  public board(){}  public void buttonpressed(){     boardmanager.methodtocall(); }  public static void main(string[] args) {     boardmanager = new boardmanager(); } } 

or this:

class board { boardmanager boardmanager;  public board(){ }  public void buttonpressed(){     boardmanager.methodtocall(); }  public static void main(string[] args) {     board b = new board();     b.boardmanager = new boardmanager(); } } 

you can't call non-static field(boardmanager) static method (main). read more static keyword.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -