Login Panel : Dialog « Swing Components « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Swing Components » Dialog 




Login Panel
   

/**
 * Class: LoginPane
 * Description: A simple class to get user's loginname and password.
 * NOTE: This class is not very secure!
 @author Le Cuong Nguyen
 **/
//package atnf.atoms.mon.util;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class LoginPane extends JDialog implements ActionListener {
  String itsUsername = "";
  String itsPassword = "";
  boolean itsFirst = true;
  boolean itsKeep = false;
  JTextField itsUserField = new JTextField(15);
  JPasswordField itsPassField = new JPasswordField(15);
  JCheckBox itsKeepBox = new JCheckBox("Save details:"false);
  boolean itsInit = false;

  public LoginPane() {
    super();
    setTitle("Login");
    setModal(true);
    getContentPane().setLayout(new GridLayout(32));
    getContentPane().add(new JLabel("Username:"));
    getContentPane().add(itsUserField);
    getContentPane().add(new JLabel("Password"));
    getContentPane().add(itsPassField);
    getContentPane().add(itsKeepBox);
    JButton submit = new JButton("done");
    getContentPane().add(submit);
    submit.addActionListener(this);
    pack();
  }

  public String[] getLogin() {
    if (!itsKeep && !itsFirst) {
      return null;
    }
    if (!itsInit) {
      return null;
    }
    itsFirst = false;
    String[] res = new String[2];
    res[0= itsUsername;
    res[1= itsPassword;
    if (!itsKeep) {
      itsUsername = "";
      itsPassword = "";
    }
    return res;
  }

  public void actionPerformed(ActionEvent e) {
    itsUsername = itsUserField.getText();
    itsPassword = new String(itsPassField.getPassword());
    itsKeep = itsKeepBox.isSelected();
    itsInit = true;
    setVisible(false);
  }
}

   
    
    
  














Related examples in the same category
1.Vista Transparent DialogVista Transparent Dialog
2.Use this modal dialog to let the user choose one string from a long list
3.Tip Of Day Dialog
4.Swing error dialog (Exception dialog)Swing error dialog (Exception dialog)
5.Swing Login Domain Dialog with animationSwing Login Domain Dialog with animation
6.Shake a dialog
7.About dialog
8.Login DialogLogin Dialog
9.The base class for standard dialogs.
10.Password Dialog
11.A popup dialog with a message and a scrollable list of items
12.Custom dialog box to enter dates
13.Dialog Panel
14.Exception dump and Dialog Box
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.