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 :

14 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. Çok farklı bloglar gerçekten deneyin bir..

    halk tv izle tv izle

    Kaynak; mobil tv

    ReplyDelete
  4. how to add both the frame??
    when i run Log.java command answer Log.java uses or override a deprecated API.
    what id o....

    ReplyDelete
  5. I all around agree with the above point that the Internet is dependably changing into the world's most bewildering viewpoints for correspondence. Hp Deskjet 3755 Wireless Setup

    ReplyDelete


  6. I'm impressed, I need to say. Very rarely do I encounter a blog that’s both informative and entertaining, and let me tell you, you’ve hit the nail on the top. Your blog is vital. If anyone need car image editing sevices then go to our website.

    ReplyDelete
  7. Really helpful and informative article.25 06 ammo bulk Thanks for sharing. Keep up the good work. Thanks for sharing. It is a nice article. I found some interesting facts about blog comments sites. It is very useful for me to create high-quality backlinks on these sites.

    ReplyDelete
  8. It’s a fantastic List for SEO. Extremely useful info specially the last part I care for such information. AVAILABLE PUPPIES I was seeking this certain information for a very long time. Thanks for sharing! please keep it up Maintains!

    ReplyDelete
  9. Excellent list! I just added your blog to pages. Thanks for sharing this wonderful list of Sites. I am making very good quality backlinks from this given the high DA sites. TESTIMONIALS Thanks for sharing! please keep it up Maintains!

    ReplyDelete

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