Java: can't see my variable -


i have small little code don't know why cannot read value of aa.width aa class in ab class.

i trying create basic game. file ab.java has print statement. know not calling function in aa, that's how java works. thought aa.width , value public variable...thanks help

aa.java :

package com.game;  import javax.swing.jframe;  public class aa {      public static ab f= new ab();     public static int width = 600;     public static int height = 400;     public static void main(string args[]){          f.setsize(width,height);         f.setresizable(false);         f.setvisible(true);         f.setdefaultcloseoperation(jframe.exit_on_close);         f.settitle("game first");         f.setlocationrelativeto(null);         system.out.println("main window running!");      } } 

ab.java

package com.game;  import java.awt.gridlayout;  import javax.swing.*;  public class ab extends jframe {      /**      *       */     private static final long serialversionuid = 1l;     public ac panel;      public ab() {         panel = new ac(this);         setlayout(new gridlayout (1,1,0,0));         add(panel);         system.out.format("the value of width %d\n", aa.width);     }  } 

it prints out :

the value of width 0 main window running! 

you setting aa.width variable after calling ab() constructor. move public static int width = 600; 1 line , done.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -