How can I make login form with java gui? this is the way to make login form in java gui and open a new form after clicking, How to make login form with java gui and open a new frame with input username and password
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.
/*
* login_form.java
*
* Created on July 16, 2013, 10:57 AM
*/
package loginform;
/**
*
* @author LTIET_CSE_DEPT
*/
public class login_form extends javax.swing.JFrame {
/** Creates new form login_form */
public login_form() {
initComponents();
jOptionPane1.setVisible(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
uname = new javax.swing.JTextField();
ok = new javax.swing.JButton();
cancel_btn = new javax.swing.JButton();
upass = new javax.swing.JPasswordField();
jOptionPane1 = new javax.swing.JOptionPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Name:");
jLabel2.setText("Password:");
ok.setText("OK");
ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okActionPerformed(evt);
}
});
cancel_btn.setText("Cancel");
cancel_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancel_btnActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(upass)
.addGroup(layout.createSequentialGroup()
.addComponent(ok)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancel_btn))
.addComponent(uname, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(84, 84, 84)
.addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(242, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(uname, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(upass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ok)
.addComponent(cancel_btn))
.addGap(28, 28, 28)
.addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(151, Short.MAX_VALUE))
);
pack();
}// //GEN-END:initComponents
private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
if(uname.getText().equals("Sagar"))
{
if(upass.getText().equals("123"))
{
jOptionPane1.showMessageDialog(this,"Welcome");
}
else{jOptionPane1.showMessageDialog(this,"Enter Correct Password");}
}
else{jOptionPane1.showMessageDialog(this,"Enter Correct UserName");}
}//GEN-LAST:event_okActionPerformed
private void cancel_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_btnActionPerformed
System.exit(0);
}//GEN-LAST:event_cancel_btnActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new login_form().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancel_btn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JOptionPane jOptionPane1;
private javax.swing.JButton ok;
private javax.swing.JTextField uname;
private javax.swing.JPasswordField upass;
// End of variables declaration//GEN-END:variables
}
0 comments:
Post a Comment