swing getcontentpane()方法 的详细页面:
impo java.awt.container;
impo javax.swing.*;
public class helloworld extends jframe {
container c = new container();
jtextfield jtf = new jtextfield(10);
jbutton jb = new jbutton("ok");
public helloworld() {
c = this.getcontentpane();
c.add(jtf);
c.add(jb);
}
public static void main(string[] args) {
jframe jf = new jframe("helloworld");
jf.setvisible(true);
jf.setsize(200, 200);
}
}
这段源码那里有错误,麻烦各位指教
你的main函数应当是helloworld jf = new helloworld("helloworld");而不是jframe jf = new jframe("helloworld");
况且,
你的contentpane还没有布局,一味的add只会使后面添加的组件覆盖之前添加的组件