java - Strange text output of e.getSource() on MouseEvent e -


i want able print mouseevent e, have seen people using getsource() method this, mine doesn't give exact output want. in other code people print e.getsource() , gives direct path image.

when print e.getsource():

javax.swing.jlabel[,224,7,23x20,alignmentx=0.0,alignmenty=0.0,border=,flags=8388608,maximumsize=,minimumsize=,preferredsize=,defaulticon=file:/c:/users/sam/workspace/rs%20calculator/bin/hitpoints_icon.png,disabledicon=,horizontalalignment=c enter,horizontaltextposition=trailing,icontextgap=4,labelfor=,text=,verticalalignment=center,verticaltextposition=center]  

this output includes image path want access - lots of other random information.

how can print image path? (/c:/users/sam/workspace/rs%20calculator/bin/hitpoints_icon.png)

    for(jlabel j : jlabelarray){         j = new jlabel(imageicons[n]);          j.addmouselistener(new mouseadapter(){              @override             public void mouseclicked(mouseevent e){                 setsize(650,400);                 system.out.println(e.getsource());                 iconclicked(e);             }          });          add(j);         n++;     } 

the source returned java correct since mouselistener added jlabel , not image. if want imageicon label contains, extract it. note you're better off using mousepressed method rather mouseclicked.

@override public void mousepressed(mouseevent e) {    jlabel label = (jlabel) e.getsource();    imageicon icon = label.geticon();    // .... } 

as side rec, troubles me:

setsize(650,400); 

you should avoid trying set sizes of things. mind if ask, trying achieve this?


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -