如何在小程序中的不同行添加文本字段?

How to add text fields in different line in applet?


我有这个带有 2 个文本字段的小程序(上面是图像)。如何将这些文本字段分隔到不同的行?

代码

import java.applet.*;
import java.awt.*;

public class Print extends Applet {
    TextField text1,text2;
    public void init(){ 
        text1=new TextField(8);
        text2=new TextField(8);  
        add(text1);
        add(text2);

    }
   public void paint(Graphics g) { 
      g.drawString("Welcome in Java Applet.",40,200);
   }
}

最简单的方法是使用 setBounds(x,y,width,height)。在您的情况下使用如下代码

text1.setBounds(10,100,100,20);
text2.setBounds(10,130,100,20);

你可以增加TextField的大小,减少panel的大小,它会自动出现在下一行

我将 textField 的大小从 10 增加到 20,它会自动出现在下一行