Inconsistent results in Eclipse for Java Swing -


i teaching myself java , reading "java in 1 desk reference dummies." using code provided in book practice swing. here code using comes book: `import javax.swing.*;

public class javabook6 extends jframe {    public static void main(string[] args)  {      new javabook6();  }  public javabook6() {     this.setsize(400, 400);     this.setlocation(500, 0);     this.setdefaultcloseoperation(exit_on_close);     this.settitle("sample");     this.setvisible(true);       jpanel pnlmain = new jpanel();     jcheckbox chkmy = new jcheckbox("save");     jbutton btnmy = new jbutton("search");     jtextfield txtmy = new jtextfield(20);      pnlmain.add(chkmy);     pnlmain.add(txtmy);     pnlmain.add(btnmy);     this.add(pnlmain);     } } 

i seem inconsistent results when press run. window shows up. however, thing displayed in window frame title , other times components such jcheckbox, jtextarea , jbutton show up, expect.

my question why components show , not others? have tried using other components , same inconsistent results.

as stated beginner , therefore have basic understanding of how java works, please forgive me if answer question obvious.

i'm not impressed text book:

  1. the gui should created on edt. read section swing tutorial on concurrency more information. recommend use examples tutorials since incorporate suggestions tutorial.

  2. component must added gui before setvisible( true ) method invoked. (there ways around this, keep simple , follow rule).


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -