Applet小程序嵌入到HTML中为什么不能正常显示布局,并且使用TencentTraveler根本不能显示?如下例:
import java.applet.*;
import java.awt.*;public class label1 extends Applet{
Label lab1,lab2,lab3;
TextField txtfld1,txtfld2,txtfld3;
public void init(){
    lab1=new Label("Name",Label.RIGHT);
    lab2=new Label("Age");
    lab3=new Label();
    lab3.setText("Sex");
    lab1.setBackground(Color.yellow);
    lab2.setBackground(Color.yellow);
    lab1.setForeground(Color.red);
    lab2.setForeground(Color.blue);
    txtfld1=new TextField(20);
    txtfld2=new TextField(20);
    txtfld3=new TextField(20);
    setLayout(null);
    add(lab1);add(txtfld1);
    add(lab2);add(txtfld2);
    add(lab3);add(txtfld3);
    lab1.setBounds(0,0,100,30);
    txtfld1.setBounds(101,0,200,30);
    lab2.setBounds(0,31,100,30);
    txtfld2.setBounds(101,31,200,30);
    lab3.setBounds(0,62,100,30);
    txtfld3.setBounds(101,62,200,30);
}
}
//<applet code=label1.class height=400 width=400></applet>
请指点,谢谢!

解决方案 »

  1.   

    setLayout(null);
    布局管理器设置为NULL了 应该不能清楚显示布局的吧,选定一种布局方式试一下
      

  2.   

    不行,已经设置过了,比如:setLayout(new GridLayout(3,2));在小程序查看器中是没有问题的,但到了网页上依然没有变化
    并且setLayout(null)叫做零布局,其实也是一种布局,可以使用setBounds(int,int,int,int)方法来设定一个控件的位置和大小,这个在小程序查看器中也是没有问题的
    谁能告诉我答案啊??!! T_T
      

  3.   

    你不应该把布局管理器设为 null,如果你设为null了,就要为你的组件指示它的位置
    你可以为你的组件调用setBounds(int x,int y,int width,int height)
      

  4.   

    设置
        lab1.setBounds(0,0,100,30);
        txtfld1.setBounds(101,0,200,30);
        lab2.setBounds(0,31,100,30);
        txtfld2.setBounds(101,31,200,30);
        lab3.setBounds(0,62,100,30);
        txtfld3.setBounds(101,62,200,30);
    放在add();的前面。