java - How to make a class extending a jLabel so that it appears as a JLabel in my main class? -


so, i'm making memory. have tile class, @ point have number, , boolean (to show if flipped or not). made duplicates of numbers tile objects , randomized them, , in turn added them layout.

basically, need them show on screen jlabels, , i'm not sure how this? should extending else, or special in tile class? or problem logic elsewhere? here's tile class @ point (very little)

ps. need use timer flippy flop

class tile extends jlabel implements actionlistener{  boolean flipped; int imagenum; imageicon image; jlabel card;  tile(int num, boolean f) {     imagenum=num;     flipped=f;     card=new jlabel(""+imagenum); } public void flipcard() {  }  public void actionperformed(actionevent a) {  } 

any appreciated! edit:

here's main class try add tiles

jpanel gridpanel = new jpanel(new gridlayout(gridsize, gridsize));     tile[][]tiles=new tile[(gridsize*gridsize)/2][2];     boolean[][]tileplaced=new boolean[(gridsize*gridsize)/2][2];     jlabel[][] cardsongrid = new jlabel[gridsize][gridsize];     for(int i=0;i<gridsize;i++)     {         for(int j=0;j<gridsize;j++)             cardsongrid[i][j]=new jlabel("");     }     for(int i=0; i<((gridsize*gridsize)/2);i++)     {         tiles[i][0]= new tile(i, true);         tiles[i][1]= new tile(i, true);         tileplaced[i][0]=false;         tileplaced[i][1]=false;     }      for(int i=0; i<gridsize;i++)     {         for(int j=0;j<gridsize;j++)         {             int tilenum = tilerandom(gridsize);             int tilenumver = (int)math.floor(math.random()*2);             while(tileplaced[tilenum][tilenumver]==true)             {                 tilenum = tilerandom(gridsize);                 tilenumver = (int)math.floor(math.random()*2);             }             gridpanel.add(tiles[tilenum][tilenumver]);             tileplaced[tilenum][tilenumver]=true;         } 

:'(

 tile(int num, boolean f){     imagenum=num;     flipped=f;     card=new jlabel(""+imagenum);//1. remove line , card label     super.settext(string.valueof(num));//add line  } 

just create object of tile

tile mylabel = new tile(10,false);//this create lable 

because tile class subclass of jlabel , no need create label in tile class tile label.apart won't action events jlabel.it's not clickable element use mouselistener.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -