swing - Java JLabel not Working -


i quite new java. decided code tic-tac-toe practice (from scratch).

anyway, trying have 'jlabel label' change when click; going 1, 2, etc. change other numbers. but, now, works test.

the 'system.out.println("number of clicks: " + mousein);' works fine, , produces output want. picture of console , jframe/jpanel/jlabel can seen here:

image

(the little 1 in jframe jlabel. want match output in console.

i have googled, , searched, , tried know (which ain't much!) , can't dang thing work...i'm asking guidance. main method includes building of jframe/panel.

code below:

from main class, called (namone.java [named own reasons]):

  public void run(jpanel p) //takes panel main method {      for(int = 0; < ticlist.length; i++){         ticlist[i] = new jbutton(buttontext); //for every position in         //ticlist[], create jbutton object           p.add(ticlist[i]);         ticlist[i].setpreferredsize(new dimension(140,140));          ticlist[i].addmouselistener(mouse); //load mouselistner      }      //set mousein click value in mouseevents class     int mousein = mouse.getclicks();     //set text value text value in mouseevents class     text = mouse.gettext();      //output...      system.out.println("number of clicks: " + mousein); //for testing     string mouse = integer.tostring(mousein); //convert mousein value (from mouseevents.java) mouse     jlabel label = new jlabel(); //new jlabel     p.add(label); //add label screen     label.settext(mouse); //set text of label value of mouse     system.out.println(mouse); //for testing     //so can see if it's working (clicks wise)     } 

and code mouseevents.java class:

public class mouseevents extends namone implements mouselistener {  int clicks = 1; string text = "first"; //for testing purposes public namone game = new namone();  public int getclicks(){     return clicks; }  public string gettext(){     return text; }  public int inttostring(){     integer.tostring(clicks);     return clicks; }  @override public void mouseclicked(mouseevent e) {     clicks++;     inttostring();           jpanel p = new jpanel();      text = "" + clicks;            game.run(p);   } 

like said. new java; i'm trying learn. i'm sure it's caused own ignorance.

thanks.

assuming mouse of type mouseevents write, 1 possibility need pass mouse.gettext() call label.settext(.).

regardless, way set game bit strange me. reason create brand new jpanel every time clicks? why not maintain original jpanel , update instead. attach custom actionlistener each jbutton runs code everytime button clicked. if actionlistener inner class, can view variables in scope jbutton defined.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -