i've searched internet solutions , don't seem find 1 works me... in case you're wondering, i'm new swing. so, here's thing, jbutton
appears, jtextarea
doesn't. don't know solve this... me out guys...
public class framecreation { public jframe createframe(int width, int height, string name) { jframe frame = new jframe(name); frame.setvisible(true); frame.setsize(width, height); frame.setlayout(null); frame.setdefaultcloseoperation(exit_on_close); frame.getcontentpane().setbackground(color.dark_gray); return frame; } public jbutton createbutton(int width, int height, int xpos, int ypos, string text) { jbutton button = new jbutton(text); button.setbounds(xpos, ypos, width, height); button.setbackground(color.gray); button.setforeground(color.white); return button; } public jtextarea createtextarea(int width, int height, int xpos, int ypos) { jtextarea txt = new jtextarea(); txt.setvisible(true); txt.setbounds(xpos, ypos, width, height); txt.settext("help poor jtextarea appear on frame..."); return txt; } } public class main { public static void main(string[] args) { framecreation mainframe = new framecreation(); jframe f = new framecreation().createframe(600, 600, "my frame"); f.add(mainframe.createbutton(100, 40, 10, 10, "click me!")); f.add(mainframe.createtextarea(200, 200, 390, 10)); } }
remove frame.setvisible(true); framecreation class, , add f.setvisible(true); in end of main method.
public static void main(string[] args) { framecreation mainframe = new framecreation(); jframe f = new framecreation().createframe(600, 600, "my frame"); f.add(mainframe.createbutton(100, 40, 10, 10, "click me!")); f.add(mainframe.createtextarea(200, 200, 390, 10)); //this new line f.setvisible(true); }