java - JFrame not presenting any Components -
i using following code create simple jframe
, reason doesn't show components, blank frame. why happening? created frames bunch of times , can't figure out wrong. code is:
main(){ jframe frame = new jframe("colorizer | by: nonamesl"); frame.setsize(400,200); frame.setlocationrelativeto(null); frame.setvisible(true); frame.setdefaultcloseoperation(jframe.exit_on_close); jpanel panel = new jpanel(); frame.setcontentpane(panel); textfield=new jtextfield("enter name!"); textfield.setbounds(0,0,40,200); textfield.setvisible(true); frame.getcontentpane().add(textfield); button=new jbutton("go!"); button.setbounds(0, 200, 40, 200); button.setvisible(true); frame.getcontentpane().add(button); rectangle=new recshape(color.white); rectangle.setbounds(0,40,400,160); rectangle.setvisible(false); frame.getcontentpane().add(rectangle); main.frame=frame; registerbutton(); }
the recshape
class class created create rectangle shape on screen. wrong?
put frame.setvisible(true);
after adding components to jframe
, , show added components. moreover, should use specific layout rather setting bounds components. can use layout manager.
Comments
Post a Comment