Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Login Form with Java GUI using Netbeans
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Melissa
Login Form with Java GUI using Netbeans
1 Answer(s)      9 months ago
Posted in : Java Beginners


Hi there!

I'm a beginner in Java. I've created 2 class files: 1) TestAssign.java 2) NewFrame.java How can I have different user to login? Now that I've only administrator who is able to login. But, I would like to have other user to login too such as end-user and general manager. How/where should I code it?

TestAssign.java

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

public class TestAssign extends JFrame{

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

    JButton blogin = new JButton("Login");
    JPanel panel = new JPanel();
    JLabel username = new JLabel("Username:");
    JLabel password = new JLabel("Password:");
    JTextField txtadmin = new JTextField(15);
    JPasswordField pass = new JPasswordField(15);

    TestAssign(){
        super("Login Authentication");
        setSize(400,300);
        setLocation(500,280);
        setResizable(false);
        panel.setLayout(null);

        username.setBounds(80, 65, 100, 20);
        password.setBounds(80, 110, 100, 20);
        txtadmin.setBounds(155, 65, 150, 20);
        pass.setBounds(155, 110, 150, 20);
        blogin.setBounds(160, 180, 80, 20);

        panel.add(blogin);
        panel.add(username);
        panel.add(password);
        panel.add(txtadmin);
        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 paname = txtadmin.getText();
                String ppaswd = pass.getText();
                if(paname.equals("admin") && ppaswd.equals("1234")){
                    NewFrame regFace = new NewFrame();
                    regFace.setVisible(true);
                    dispose();
                }else{
                    JOptionPane.showMessageDialog(null, "Invalid Password / "
                            + "Username");
                    txtadmin.setText("");
                    pass.setText("");
                    txtadmin.requestFocus();
                    }
                }
        });
    }
}

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 MYSOFT Sdn Bhd!******", 
            SwingConstants.CENTER);
    JLabel dms = new JLabel("Delivery Management System");
    JPanel panel = new JPanel();

    NewFrame(){
        super("Welcome!");
        setSize(400,300);
        setLocation(500,280);
        setResizable(false);
        panel.setLayout(null);

        welcome.setBounds(60, 70, 300, 60);
        dms.setBounds(125, 100, 300, 60);

        panel.add(welcome);
        panel.add(dms);

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

Thanks in advance.


Advertisement
View Answers

January 28, 2014 at 11:39 PM


I just found out the solution. In the TestAssign.java, I'll need else-if statement and create a new frame for both of the manager and staff. For example, ManagerFrame and StaffFrame.

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

public class TestAssign extends JFrame{

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

    JButton blogin = new JButton("Login");
    JPanel panel = new JPanel();
    JLabel username = new JLabel("Username:");
    JLabel password = new JLabel("Password:");
    JTextField txtuser = new JTextField(15);
    JPasswordField pass = new JPasswordField(15);

    TestAssign(){
        super("Login Authentication");
        setSize(400,300);
        setLocation(500,280);
        setResizable(false);
        panel.setLayout(null);

        username.setBounds(80, 65, 100, 20);
        password.setBounds(80, 110, 100, 20);
        txtuser.setBounds(155, 65, 150, 20);
        pass.setBounds(155, 110, 150, 20);
        blogin.setBounds(160, 180, 80, 20);

        panel.add(blogin);
        panel.add(username);
        panel.add(password);
        panel.add(txtuser);
        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 paname = txtuser.getText();
                String ppaswd = pass.getText();
                if(paname.equals("admin") && ppaswd.equals("1234")){
                    NewFrame regFace = new NewFrame();
                    regFace.setVisible(true);
                    dispose();
                }
                else if(paname.equals("manager") && ppaswd.equals("4567")) {
                    ManagerFrame manager = new ManagerFrame();
                    manager.setVisible(true);
                    dispose();              
                }
                else if(paname.equals("staff") && ppaswd.equals("7890")) {
                    EndUserFrame staff = new EndUserFrame();
                    staff.setVisible(true);
                    dispose();              
                }
                else{
                    JOptionPane.showMessageDialog(null, "Invalid Password / "
                            + "Username");
                    txtuser.setText("");
                    pass.setText("");
                    txtuser.requestFocus();
                    }
                }
        });
    }
}


Related Tutorials/Questions & Answers:
Login Form with Java GUI using Netbeans
Login Form with Java GUI using Netbeans  Hi there! I'm a beginner in Java. I've created 2 class files: 1) TestAssign.java 2) NewFrame.java How can I have different user to login? Now that I've only administrator who is able
plz help me to create gui using Java netbeans
plz help me to create gui using Java netbeans  Hi, I am unable to fetch a particular data from DB.I am using netbeans for creating GUI. If I want to fetch a particular value like '6', it is calling all the data which contains 6
Advertisements
login form using java bean in eclipse
login form using java bean in eclipse  I have made a college community website but i need to implement beans to my login and contact us page. how can i do
Creating Login Page In JSF using NetBeans
illustrates you how to create a login form in JSF using NetBeans. To create the jsp page in NetBeans: 1. Right click on Web Pages under your project. 2. Go to New- JSP... Creating Login Page In JSF using NetBeans  
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
Using java script do login form having fields with condition.
Using java script do login form having fields with condition.  Need a login form with username, password, phone no, email id, date fields. We should specify the conditions for each field and if we press the submit button
standart login form for messenger in java
standart login form for messenger in java  hi i need login from for chating messenger in java. but its structure would like this Home Register Login User ID Password   Hi Friend
standart login form for messenger in java
standart login form for messenger in java  hi i need login from for chating messenger in java. but its structure would like this Home Register Login User ID Password   Hi Friend
Login Form in Java - Java Beginners
Login Form in Java  Hi, In my Project, I am using Java-JDBC-Mysql...) How to create frontage form in java to validate it. regards, Prashant...*; import java.awt.*; import java.awt.event.*; import java.sql.*; class Form
Login Form using Ajax
;/action> Develop a Login Form Using Ajax : The GUI of the application...Login Form using Ajax       This section provides you an easy and complete implementation of login form
How to send from netbeans gui registration form to MySQL query browser database?
How to send from netbeans gui registration form to MySQL query browser database?  Well i have a Registration form GUI in my netbeans. in my GUI... Registration form GUI. public class Register extends javax.swing.JFrame { public
How to send from netbeans gui registration form to MySQL query browser database?
How to send from netbeans gui registration form to MySQL query browser database?  Well i have a Registration form GUI in my netbeans. in my GUI... Registration form GUI. public class Register extends javax.swing.JFrame { public
how to save a gui form in core java
how to save a gui form in core java  please help me i am java beginner how to save a jframe containing jtable and panels in java thank you
Login form using Jsp in hibernate - Hibernate
Login form using Jsp in hibernate   Hai Friend, As I new To hibernate, I'm facing problem in My project(JSP with hibernate).. My login form... and entering into Menu Form.. plz can any one help for my problem... Thanks
Which one is better for creating a GUI using swings either Manual coding or IDE(NetBeans,eclipse)..? drag and dropping components
Which one is better for creating a GUI using swings either Manual coding or IDE(NetBeans,eclipse)..? drag and dropping components  I am beginner in java application developing.... Which one is better for creating a GUI using
login form
login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components prepsent in that form are getting clearedup using frameobject.setVisible(false
Login Form
of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so...Login Form  I have 8 jsp pages.Each of them has three columns:Left
Login Form
of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so...Login Form  I have 8 jsp pages.Each of them has three columns:Left
Database driven login form - Java Server Faces Questions
Database driven login form  Dear sir,madam, Greetings!! well, am a new user of java and i am programming using the netbeans IDE, what i need is code that; will create a database driven login form where users are authenticated
login form
login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components prepsent in that form are getting clearedup using frameobject.setVisible(false
How to put the logo in login form using swings/awt?
How to put the logo in login form using swings/awt?  Hi, How to put the logo in login form using swings/awt? I write the login form is working... that will display logo along with login form in Java Swing. import javax.swing.
add cookies to login form in jsp by using struts2.0 framework
add cookies to login form in jsp by using struts2.0 framework  hi sir... struts2.0 and hibernate3.0 and mysql database for login .jsp now i want to add cookies to above form please help me
How to Create Login/ Registration Form using PHP and MYSQL
How to Create Login/ Registration Form using PHP and MYSQL  Hi, I am learning PHP. I have some dilemma how to create a Login Form and make connectivity with HTML page using PHP and MYSQL. Is there any body can guide me
login and registration form using servlet and authentication through mysql
login and registration form using servlet and authentication through mysql  i made a simple login and rgistration form using servlet... help here is my code...plz chk the web.xml file also index.jsp(login form) <
Display Logo on login form using swing
Display Logo on login form using swing In this tutorial, you will learn how to display a logo in login form using swing components. Here is an example where... a logo for this login form, we have used ImageIcon class that accepts the image
Java Programming using Netbeans - IDE Questions
Java Programming using Netbeans  Hello Dear sir, i got one scenario... & address using netbeans jframe then i have to store these data into my package so... visit the following link: http://www.roseindia.net/java/example/java/swing/add
Looking for sample project in java using netbeans
Looking for sample project in java using netbeans  Hi all, i am novice in developing desktop application in java using netbeans. can anyone pls help me by sending project built in netbeans as soon as possible. so that i could
administrator login form
administrator login form   Hi iam using struts frame work backend as oracle .i want code for administrator login form thanks in advance
Java using Netbeans Object Oriented Programming
Java using Netbeans Object Oriented Programming   I am trying to make a program that uses a main class and a separate class with one public method and one private method. The main method in the main class asks the user for 2
java netbeans
java netbeans  i am making project in core java using Netbeans. Regarding my project i want to know that How to fetch the data from ms-access... using netbeans
java netbeans
java netbeans  i am making project in core java using Netbeans. Regarding my project i want to know that How to fetch the data from ms-access... using netbeans
Advertisements
 

 

 

DMCA.com