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>
请指点,谢谢!
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>
请指点,谢谢!
布局管理器设置为NULL了 应该不能清楚显示布局的吧,选定一种布局方式试一下
并且setLayout(null)叫做零布局,其实也是一种布局,可以使用setBounds(int,int,int,int)方法来设定一个控件的位置和大小,这个在小程序查看器中也是没有问题的
谁能告诉我答案啊??!! T_T
你可以为你的组件调用setBounds(int x,int y,int width,int height)
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();的前面。