Creating Simple Login Form in Java Programmer. Java is a very popular programming language of many existing programming languages. With java, we can create customized applications for desktop PC or Laptop. Javais applied in addition to customize the desktop, can also be applied in the other. When creating an application with a java program language, usually requiring no Login Form and some are not. Here is a program to create a login form that you can apply to the application you want to create using the Java programming language.
This is a coding for Login From in Java :
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Login{
public Login(){
final JFrame frm = new JFrame();
frm.setResizable(false);
frm.setTitle("Login Form");
JLabel lblName = new JLabel("NAME ");
JLabel lblPass = new JLabel("PASSWORD ");
final JTextField txtName = new JTextField(20);
final JPasswordField txtPass = new JPasswordField(20);
JButton btnLogin = new JButton("LOGIN");
JButton btnExit= new JButton("EXIT");
final JDesktopPane desktop = new JDesktopPane();
desktop.setBackground(Color.LIGHT_GRAY);
frm.setContentPane(desktop);
//button login (btnLogin)
btnLogin.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){
String sms ="";
int tipeSms = 0;
if (!txtName.getText().equals("hermantos")){
txtName.setText("");
txtName.requestFocus();
sms = "Name not known";
tipeSms = JOptionPane.ERROR_MESSAGE;
}else if (!String.valueOf
(txtPass.getPassword()).equals("hermantos")){
txtPass.setText("");
txtPass.requestFocus();
sms = "Wrong Password";
tipeSms = JOptionPane.ERROR_MESSAGE;
}else if((txtName.getText().equals("hermantos"))&& (String.valueOf
(txtPass.getPassword()).equals("hermantos"))){
txtName.requestFocus();
sms = "Login Succesfull !!";
tipeSms = JOptionPane.INFORMATION_MESSAGE;
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}catch (Exception ignored){
}
frm.dispose();
}
if (!sms.equals("")){
JOptionPane.showMessageDialog(null, sms,"Wrong Password", tipeSms);
}
}
});
//aksi pada button exit (btnExit)
btnExit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
Container contentPane = frm.getContentPane();
contentPane.setLayout(null);
contentPane.add(lblName);
contentPane.add(txtName);
contentPane.add(lblPass);
contentPane.add(txtPass);
contentPane.add(btnLogin);
contentPane.add(btnExit);
Insets insets = contentPane.getInsets();
lblName.setBounds(insets.left + 30,
insets.top + 30, 80, 20);
lblPass.setBounds(insets.left +30 ,
insets.top + 80, 150, 20);
txtName.setBounds(insets.left +110 ,
insets.top + 20, 150, 30);
txtPass.setBounds(insets.left +110,
insets.top + 70, 150, 30);
btnLogin.setBounds(insets.left +40,
insets.top + 120, 100, 40);
btnExit.setBounds(insets.left +150,
insets.top + 120, 100, 40);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(new Dimension(300, 200));
frm.setVisible(true);
frm.setLocationRelativeTo(null);
}
//method main
public static void main(String[] args){
new Login();
}
}
For blue text, you can change to what you want and are listed merely as an example. After that, save the program with Login.java name in order to run or compile. And it will appear later as follows:
To login, then enter the name and password that has been set previously, namely :
Name : hermantos
Password : hermantos.
And click button Login. If you've made changes to the next are colored blue, then enter the match what you type on the program. Benefical for the needy. Thank you for visiting and reading the article Creating Simple Login Form in Java Programming.
Tags : Java programming, Login in Java, Create Form Login, Java Login Program.
1 Komentar untuk "Creating Simple Login Form in Java Programming"
thank you!