Code:
import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JTextField;
 
 
public class AlignEx extends JApplet{
       
        public void init(){
               
                
                this.getContentPane().setLayout(new FlowLayout());
 
    
                JTextField MyTxtfield = new JTextField(" Horizontal Alignment", 10);
               
               
               
                int horizontalAlignment = MyTxtfield.getHorizontalAlignment();
               
                switch(horizontalAlignment){
               
                        case JTextField.LEFT:
                                MyTxtfield.setText("Left");
                                break;
                        case JTextField.RIGHT:
                                MyTxtfield.setText("Right");
                                break;
                        case JTextField.CENTER:
                                MyTxtfield.setText("Center");
                                break;
                        case JTextField.LEADING:
                                MyTxtfield.setText("Leading");
                                break;
                        case JTextField.TRAILING:
                                MyTxtfield.setText("Trailing");
                                break;
                }
              
                add(MyTxtfield);
               
        }
}