Example for Login Event in Java AWT Container
import java.awt.*;
import java.awt.event.*; //import Action Event classes
class MyFrame
{
Frame f;
Button b1,b2;
TextField tf1,tf2;
Label l1,l2;
TextArea ta1;
public MyFrame() //Creating a Constructor
{
f = new Frame("This is My First Frame");
b1 = new Button("Login");
b2 = new Button("Cancel");
l1 = new Label("Username");
l2 = new Label("Password");
tf1 = new TextField("",20);
tf1.setBounds(350,100,100,80);
tf2 = new TextField("",20);
tf2.setEchoChar('*'); //Hide Charactor to the Password Fields
tf1.setBounds(350,100,100,80);
ta1 = new TextArea("Write an Long Comments");
f.setLayout(new FlowLayout());
f.setLocation(30,40);
f.add(l1);
f.add(tf1);
f.add(l2);
f.add(tf2);
f.add(b1);
f.add(b2);
f.setSize(300,400);
f.setVisible(true);
//Creating An Action to Login
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String username = tf1.getText();
String pass = tf2.getText();
String user = "bschandel";
String password = "mspatel";
if(username.equals(user) && pass.equals(password))
{
System.out.println("Login Successful");
}
else
{
System.out.println("Login FAILED ! ");
}
}
});
//Action Event Close
}
public static void main(String args[])
{
new MyFrame(); //Creating an Object
}
}
Save this file : MyFrame.java
Compile this file : javac MyFrame.java
Run this file : java MyFrame
Note : Just do Two Clicks on Advertising(ADS) on this page.
If this information is important to you , and you want to , I will continue writing some more details of programming language, so click on the advertising, available on this page. This is motivate me for writing some more blogs.
Comments
Post a Comment