GUI Login Example
//Login Class on its own Java File
import [Link].*;
import [Link].*;
import [Link].*;
public class Login extends JFrame {
public static void main(String[] args) {
Login frame = new Login();
}
JButton blogin = new JButton("Login");
JPanel panel = new JPanel();
JTextField txuser = new JTextField(15);
JPasswordField pass = new JPasswordField(15);
Login()
{
super("Login Authentication");
setSize(300,200);
setLocation(500,280);
[Link] (null);
[Link](70,30,150,20);
[Link](70,65,150,20);
[Link](110,100,80,20);
[Link](blogin); [Link](txuser); [Link](pass);
getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1|Page
setVisible(true);
actionlogin();
}
//Method to check for login
public void actionlogin(){
[Link](new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String name = [Link]();
String password = [Link]();
//Checking whether the password keyed in is correct
if([Link]("test") && [Link]("12345")) {
//If Login is successful it calls the class Welcome
Welcome regFace =new Welcome();
[Link](true);
dispose();
}
else {
[Link](null,"Wrong Password / Username");
[Link]("");
[Link](""); [Link]();
}
}
});
}
}
2|Page
//Class Welcome in a different Java File
import [Link].*;
import [Link].*;
import [Link].*;
public class Welcome extends JFrame {
public static void main(String[] args) {
Welcome frame = new Welcome();
}
JLabel welcome = new JLabel("Welcome to MMU");
JPanel panel = new JPanel();
NewFrame(){
super("Welcome");
setSize(300,200);
setLocation(500,280);
[Link] (null);
[Link](70,50,150,60);
[Link](welcome);
getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
3|Page