Home » , » How to Make Login Form With Java GUI and Open a New Frame after Log in

How to Make Login Form With Java GUI and Open a New Frame after Log in

With this source code, you can make a login form with java gui and then, when you click at login button, you will redirect to a new frame in java gui, this is very important if you want to make a big project with java. This is will make securable program. With this frame, you must type your username and password.

In this Frame, I make username as a "test" and password "12345"

You can increase your creativity with this source. And you can add a new Label or Button to make a best program. I'll give you a source code. You must save this code with name"Log.java".

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Log extends JFrame {

public static void main(String[] args) {
Log frameTabel = new Log();
}

JButton blogin = new JButton("Login");
JPanel panel = new JPanel();
JTextField txuser = new JTextField(15);
JPasswordField pass = new JPasswordField(15);

Log(){
super("Login Autentification");
setSize(300,200);
setLocation(500,280);
panel.setLayout (null);


txuser.setBounds(70,30,150,20);
pass.setBounds(70,65,150,20);
blogin.setBounds(110,100,80,20);

panel.add(blogin);
panel.add(txuser);
panel.add(pass);

getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
actionlogin();
}

public void actionlogin(){
blogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String puname = txuser.getText();
String ppaswd = pass.getText();
if(puname.equals("test") && ppaswd.equals("12345")) {
newframe regFace =new newframe();
regFace.setVisible(true);
dispose();
} else {

JOptionPane.showMessageDialog(null,"Wrong Password / Username");
txuser.setText("");
pass.setText("");
txuser.requestFocus();
}

}
});
}
}

And you must save this source below with name "newframe.java"


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class newframe extends JFrame {

public static void main(String[] args) {
newframe frameTabel = new newframe();
}

JLabel welcome = new JLabel("Welcome to a New Frame");
JPanel panel = new JPanel();

newframe(){
super("Welcome");
setSize(300,200);
setLocation(500,280);
panel.setLayout (null);

welcome.setBounds(70,50,150,60);

panel.add(welcome);

getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

}


Both of sources will give you a frame like this :


if you click login button, you will redirect to a new frame like this :


Share this article :

4 comments:

  1. Wow! This can be one particular of the most useful blogs We’ve ever arrive across on this subject. Actually Magnificent. I am also a specialist in this topic therefore I can understand your hard work.
    website design

    ReplyDelete
  2. just neede a help
    i have done the above program in applet
    so how can i get "Welcome "on a new window after clicking login
    plzz help

    ReplyDelete
  3. Thanks for the information. Helped us to convince most on how this process works and what they could achieve by following these guidelines

    Bangalore Web Designing Company, Web Development Company Bangalore

    ReplyDelete

 
Copyright © Online Business - All Rights Reserved
Proudly powered by Blogger