Tutorial Java : Swing Login Form di Java

Tutorial belajar java : membuat aplikasi login form sederhana menggunakan swing netbeans ide java khusus pemula, tutorial java lengkap di sector code

Belajar Java Pemula - Membuat form login java menggunakan class swing NetBeans IDE dan menggunakan database mysql serta koneksi kedatabasenya menggunakan jdbc yang sudah kami jelaskan sebelumnya, baca kembali tutorial java berikut : Tutorial CRUD (Create,Read,Update,Delete) Java JDBC Database MySql, dan juga Tutorial Java : Membuat Koneksi Database MySQL JDBC Driver pada Java Netbeans, Tutorial java khusus pemula kali ini kita akan membuat aplikasi sederhana login form menggunakan swing di netbeans ide. simak tutorialnya ya..

Buatlah project baru di netbeans ide, project java > java aplications dan beri nama "aplikasilogin.java", jika sudah selesai lanjut kita akan membuat sebuah database menggunakan mysql, buat kamu yang belum bisa membuat database silahkan baca Tutorial Lengkap Cara Membuat Database MySQL di PhpMyAdmin, atau bisa juga menyimak tutorial membuat form login sederhana dengan java ini sampe habis ya.
Tutorial Java : Swing Login Form di Java

Membuat database login sederhana

Pada netbeans ide, jendela services pilih database > dan klik kanan MYSQL Servers > create new database, buatlah nama database kamu "aplikasilogin" dan ok. selanjutnya membuat tabel dan kolom database "aplikasilogin". pada connection "jdbc:mysql://localhost:3306/aplikasilogin?zeroDateTimeBehavior=convertToNull [root on Default schema]" pilih nama database "aplikasilogin" dan klik kanan pada table > create table, isikan nama tabel dengan nama "user". selanjutnya add column. isiskan nama colomn "id,username,password" untuk detail pembuatan tabel dan kolom silahkan lihat gambar berikut :

Selesai membuat database MySQL kembali ke jendela project java pada NetBeans IDE.

Membuat Form Login Java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aplikasilogin;
/**
 *
 * @author b0x
 */
public class NewClass {
    public static boolean authenticate(String username, String password) {
        // hardcoded username and password
        if (username.equals("sectorcode") && password.equals("ganteng")) {
            return true;
        }
        return false;
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aplikasilogin;
/**
 *
 * @author b0x
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
 
public class loginclass extends JDialog {
 
    private JTextField tfUsername;
    private JPasswordField pfPassword;
    private JLabel lbUsername;
    private JLabel lbPassword;
    private JButton btnLogin;
    private JButton btnCancel;
    private boolean succeeded;
 
    public loginclass(Frame parent) {
        super(parent, "Login", true);
        //
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints cs = new GridBagConstraints();
 
        cs.fill = GridBagConstraints.HORIZONTAL;
 
        lbUsername = new JLabel("Username: ");
        cs.gridx = 0;
        cs.gridy = 0;
        cs.gridwidth = 1;
        panel.add(lbUsername, cs);
 
        tfUsername = new JTextField(20);
        cs.gridx = 1;
        cs.gridy = 0;
        cs.gridwidth = 2;
        panel.add(tfUsername, cs);
 
        lbPassword = new JLabel("Password: ");
        cs.gridx = 0;
        cs.gridy = 1;
        cs.gridwidth = 1;
        panel.add(lbPassword, cs);
 
        pfPassword = new JPasswordField(20);
        cs.gridx = 1;
        cs.gridy = 1;
        cs.gridwidth = 2;
        panel.add(pfPassword, cs);
        panel.setBorder(new LineBorder(Color.GRAY));
 
        btnLogin = new JButton("Login");
 
        btnLogin.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                if (Login.authenticate(getUsername(), getPassword())) {
                    JOptionPane.showMessageDialog(LoginDialog.this,
                            "Hi " + getUsername() + "! You have successfully logged in.",
                            "Login",
                            JOptionPane.INFORMATION_MESSAGE);
                    succeeded = true;
                    dispose();
                } else {
                    JOptionPane.showMessageDialog(LoginDialog.this,
                            "Invalid username or password",
                            "Login",
                            JOptionPane.ERROR_MESSAGE);
                    // reset username and password
                    tfUsername.setText("");
                    pfPassword.setText("");
                    succeeded = false;
 
                }
            }
        });
        btnCancel = new JButton("Cancel");
        btnCancel.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
        JPanel bp = new JPanel();
        bp.add(btnLogin);
        bp.add(btnCancel);
 
        getContentPane().add(panel, BorderLayout.CENTER);
        getContentPane().add(bp, BorderLayout.PAGE_END);
 
        pack();
        setResizable(false);
        setLocationRelativeTo(parent);
    }
 
    public String getUsername() {
        return tfUsername.getText().trim();
    }
 
    public String getPassword() {
        return new String(pfPassword.getPassword());
    }
 
    public boolean isSucceeded() {
        return succeeded;
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aplikasilogin;
/**
 *
 * @author b0x
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class Main {
    public static void main(String[] args) {
        final JFrame frame = new JFrame("JDialog Demo");
        final JButton btnLogin = new JButton("Click to login");
 
        btnLogin.addActionListener(
                new ActionListener(){
                    public void actionPerformed(ActionEvent e) {
                        LoginDialog loginDlg = new LoginDialog(frame);
                        loginDlg.setVisible(true);
                        // if logon successfully
                        if(loginDlg.isSucceeded()){
                            btnLogin.setText("Hi " + loginDlg.getUsername() + "!");
                        }
                    }
                });
 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 100);
        frame.setLayout(new FlowLayout());
        frame.getContentPane().add(btnLogin);
        frame.setVisible(true);
    }
}
Jangan sungkan - sungkan untuk bertanya jika belum mengerti, jika masih bingung dengan tutorial membuat form login diatas silahkan lihat video tutorial java berikut :

terima kasih.

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Tutorial Java : Swing Login Form di Java
Tutorial Java : Swing Login Form di Java
Tutorial belajar java : membuat aplikasi login form sederhana menggunakan swing netbeans ide java khusus pemula, tutorial java lengkap di sector code
https://2.bp.blogspot.com/-D6HAieOcd3k/VjrU0ranEGI/AAAAAAAABCk/SO24_ttcmeU/s320/aplikasi-login-swing-java.jpg
https://2.bp.blogspot.com/-D6HAieOcd3k/VjrU0ranEGI/AAAAAAAABCk/SO24_ttcmeU/s72-c/aplikasi-login-swing-java.jpg
KODE AJAIB
https://www.kodeajaib.com/2015/11/tutorial-java-swing-login-form-di-java.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2015/11/tutorial-java-swing-login-form-di-java.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy