Join us on Facebook

Please wait..10 Seconds Cancel

10.24.2013

// // Leave a Comment

Create a login form with required validations and all dialog box.

Login Form With Dialog Box

A Dialog window is an independent subwindow meant to carry temporary notice apart from the main Swing Application Window. Most Dialogs present an error message or warning to a user, but Dialogs can present images, directory trees, or just about anything compatible with the main Swing Application that manages them.
import javax.swing.*; import java.awt.event.*; package login_form; public class Login_Frame extends JFrame { public Login_Frame() { initComponents(); Display_Dialog.setVisible(false); } private void initComponents() { JTextField Uname_Text = new JTextField(); JPasswordField Password_Text = new JPasswordField(); JLabel Uname_label = new JLabel(); JLabel Password_label = new JLabel(); JButton Submit_Button = new JButton(); JButton Reset_Button = new JButton(); JOptionPane Display_Dialog = new JOptionPane(); Uname_Text.setToolTipText("Enter Username"); Uname_Text.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Uname_TextActionPerformed(evt); } }); Uname_label.setText("Username"); Password_label.setText("Password"); Submit_Button.setText("Submit"); Submit_Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Submit_ButtonActionPerformed(evt); } }); Reset_Button.setText("Exit"); Reset_Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Reset_ButtonActionPerformed(evt); } }); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); pack(); } private void Submit_ButtonActionPerformed(ActionEvent evt) { if(Uname_Text.getText().equals("Username")) { if(Password_Text.getText().equals("ABC")) { Display_Dialog.showMessageDialog(this,"You have Successfully Logged In"); } else { Display_Dialog.showMessageDialog(this,"You have Entered Wrong Password"); } } else { Display_Dialog.showMessageDialog(this,"You have Entered Wrong Username"); } } private void Reset_ButtonActionPerformed(ActionEvent evt) { System.exit(0); } public static void main(String args[]) { new Login_Frame().setVisible(true); } }

0 comments:

Post a Comment