Sample Output:
Required Code:
import java.awt.*;
import java.awt.event.*;
class LoginFrame extends Frame implements ActionListener
{
Label l1,l2;
TextField tf1,tf2;
Button b1;
String status="";
LoginFrame()
{
this.setVisible(true);
this.setSize(500,500);
this.setBackground(Color.green);
this.setTitle("Login Frame");
this.setLayout(new FlowLayout());
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
l1=new Label("User Name:");
l2=new Label("Password:");
tf1=new TextField(20);
tf2=new TextField(20);
tf2.setEchoChar('*');
b1=new Button("Login");
b1.addActionListener(this);
Font f=new Font("arial",Font.BOLD,20);
l1.setFont(f);
l2.setFont(f);
tf1.setFont(f);
tf2.setFont(f);
b1.setFont(f);
this.add(l1);
this.add(tf1);
this.add(l2);
this.add(tf2);
this.add(b1);
}
public void actionPerformed(ActionEvent ae)
{
String uname=tf1.getText();
String upwd=tf2.getText();
if(uname.equals("aditya") && upwd.equals("picture"))
{
status="success";
}
else
{
status="failure";
}
repaint();
}
public void paint(Graphics g)
{
Font f=new Font("arial",Font.BOLD,30);
g.setFont(f);
g.drawString("Status:Login "+status,50,300);
}
}
class TextFieldEx1
{
public static void main(String[] args)
{
LoginFrame lf=new LoginFrame();
}
}
Description:
So as we see, it is a matter of using AWT concept. The import statement which imports the awt.events.* package will be helpful to use the classes, interfaces and pre-defined methodssuch as ActionListener, windowAdapter and so on.
First the textfields and buttons are to be created, which will be useful to enter data and tap for the required operation. Then the window size, windows colour and the alphabet style should be defined whose format can be seen from the code. One thing is to be noted here is that to make visible all the graphics you want, we have to use a pre-defined method paint() . Another notable point here is that one should never forget to write the repaint() method, which is responsible to refresh the login frame.
Please note that, to get the window closing button you must write the pre-defined windowClosing() forgetting which we will be missing the most important thing, the window closing button!!
So try this one and see if you get the output. If you face any bug, comment below the problem or feel free to contact me, you can find the contact details are mentioned in my profile.



Developer, Tinkere, a proud Dad.. love to spend my available time playing with Tech!!