Search code examples
javaappletnewlinetextfieldlayout-manager

How to add text fields in different line in applet?


My Applet with text field
I have this applet (above is the image) with 2 text field. How do I separate these text fields to different lines?

code

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);
   }
}

Solution

  • The simplest method is using setBounds(x,y,width,height). In your case use code as below

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