This article is based on the Java Program to create Login Window using AWT Controls. Here we will use the AWT components Label, Button and Textfield. We will see the code to create a user_name and password text field with login and signup buttons.
AWT program in Java with output:
Awt Program in java with Output to Create Login Window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import java.awt.*; import java.awt.event.*; class LoginWindowAWT extends Frame { //Declaring text fields and Buttons TextField userName, password; Button btn1, btn2; LoginWindowAWT() { setLayout(new FlowLayout()); this.setLayout(null); //Setting the name and password that will be displayed Label u_name = new Label("User Name:",Label.CENTER); Label pass = new Label("Password:",Label.CENTER); //username declaration userName = new TextField(20); this.add(u_name); this.add(userName); //Password declaration password = new TextField(20); this.add(pass); this.add(password); password.setEchoChar('#'); //Button Declaration btn1 =new Button("LogIn"); btn2 =new Button("SignUp"); this.add(btn1); this.add(btn2); //Setting the display Bounds userName.setBounds(200,100,90,20); u_name.setBounds(70,90,90,40); password.setBounds(200,140,90,20); pass.setBounds(70,130,90,40); btn1.setBounds(100,260,70,40); btn2.setBounds(180,260,70,40); } public static void main(String args[]) { //creating an object LoginWindowAWT ml=new LoginWindowAWT(); //background Color ml.setBackground(Color.RED) ; ml.setTitle("Login Window AWT"); ml.setVisible(true); ml.setSize(400,400); } } |
Output: Save the file with .java extension and open the command prompt on that directory and run the following code.
C:\java>javac LoginWindowAWT.java
C:\java>java LoginWindowAWT
You will see the following result:

This is the end of the article to create a Login Window with an AWT program in Java with output.
Learn more about Java Programs.