java - Why is my component an instance of JRootPane if I never assigned it to one? -
let me explain code does: have created own class extends jdialog. class, lets call class a, contains a: jmenubar, jmenu, jmenuitem, jbutton, jdialog, jpanel , mouseadapter. project similar freecell game, in trying move multiple images, in own jpanels. right now, issue this: when user clicks on on screen, point coordinated of clicked , set component
component component = getcomponentat(point);
i check see if instance of jpanel, ie card
if (component instanceof jpanel)
so can move card around. problem arrises. when print out components class is, states jrootpane, have never used or seen object in entire life, until looked now. know why component object of jrootpane when never used use it.
no matter click on screen, keeps stating component jrootpane...
it because jrootpane contains jdialog? https://docs.oracle.com/javase/7/docs/api/javax/swing/jrootpane.html
it because jrootpane contains jdialog?
no jrootpane doesn't contain jdialog. jdialog contains jrootpanel.
i know why component object of jrootpane when never used use it.
component component = getcomponentat(point);
so container getcomponentat(...)
refer to? dialog, or panel?
in case looks getcomonentat()
method relative dialog , therefore return component relative dialog. since first component added dialog jrootpane returns root pane.
what want add mouselistener panel contains images. in mouselistener code do:
@override public void mousepressed(mouseevent e) { component parent = e.getcomponent(); component child = parent.getcomponentat(...); }
then if click on component containing image component.
Comments
Post a Comment