Code:
import java.awt.Color;
import java.awt.FlowLayout;
 
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.border.Border;
 
 
 
public class SetBorderExa extends JApplet{
       
        public void init(){
               
                
                this.getContentPane().setLayout(new FlowLayout());
 
                JTextField Myfield = new JTextField("Border Example",20);
               
                
                Border bor = BorderFactory.createLineBorder(Color.red);
               
                               
                Myfield.setBorder(bor);
               
                add(Myfield);
 
        }
 
}