java - Paint not showing up -
i using jframe , pane , trying draw simple square. painting not showing up. made set color black should visible. code:
package w2; import java.awt.color; import java.awt.container; import java.awt.graphics; import javax.swing.*; public class w2 { jframe frame = new jframe("w2"); public w2(){ container pane = new container(); frame.setcontentpane(pane); frame.setsize(750,500); frame.setlocationrelativeto(null); frame.setresizable(false); frame.setvisible(true); } public void paint(graphics g){ g.setcolor(color.black); g.fillrect(50, 50, 50, 50); } public static void main(string args[]){ new w2(); } }
the paint
method won't called because it's not part of object can painted.
see performing custom painting details how painting done in swing
for example...
frame.setcontentpane(new jpanel() { @override protected void paintcomponent(graphics g) { super.paintcomponent(g); g.setcolor(color.black); g.fillrect(50, 50, 50, 50); } });
Comments
Post a Comment