Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDialog as a LoginScreen.

843805Nov 28 2006 — edited Nov 28 2006
Dear people,

I want to use a JDialog as a loginscreen. But i can't get it fixed to get a proper loginscreen. I want to have a login-screen that has a label loginID whith on it rigth a textfield, beneath that must be a label with the text password with on his right a passwordfield, beneath that there must be 2 buttons named login and cancel.

I now have the folowing code, but the strings aren't be filled, so i get a nullpointerexception. Is there someone who can help me fix this problem.

My program has to show first a loginscreen, where is asked for your loginID and password. This is checked first and then the main program is started.....

the code (it's a bit messy, sorry for that.....)
/*
 * RTMOperator.java
 *
 * Created on 3 november 2006, 9:31
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package MainGUI;

import MainGUI.ProjectBuilder.StartProjectScreen;
import java.awt.*;
import javax.swing.*;

/**
 * 
 * 
 * @author hoekstraj
 * 
 * Hier wordt het programma gestart, vanuit hier moet ook het login-window worden
 * geinitaliseerd en hier wordt ook de data opgevangen welke van het login-window
 * afkomt. Vanuit hier wordt dan ook MainFrame geladen, wat nu nog niet gebeurd.
 * Dit wordt nog aangepast, maar is van mindere prioriteit momenteel.
 */
public class RTMOperator extends JDialog  {
        
      private static  String userID, password;
      private boolean login_correct=false;
      private static  LoginScreen p_login_screen = null;
      
      private final JTextField userIDField = new JTextField();
      private final JPasswordField passwordField = new JPasswordField();
      private final JButton b_login = new JButton();
 
      
    /**
     * Creates a new instance of RTMOperator
     */
    public RTMOperator(Frame owner) {
    
    super(owner, "Login Dialog", true);
    getContentPane().setLayout(new GridLayout(0,2,5,5));
    getContentPane().add(new JLabel("UserID:"));
    getContentPane().add(userIDField);
    getContentPane().add(new JLabel("Password:"));
    getContentPane().add(passwordField);
    
    b_login.setText("login");
     b_login.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_loginActionPerformed(evt);
            }
        });
        
    getContentPane().add(b_login);
    pack();
     centerOnScreen(this);
    userIDField.requestFocus();
    show();
    }
    
     private void b_loginActionPerformed(java.awt.event.ActionEvent evt) {
         userID= userIDField.getText();
         password = (new String (passwordField.getPassword()));
         if(p_login_screen.logged_in(userID, password)){
        RTMProperties.eventshistory.append(RTMProperties.time+" User logged in \n");     
        MainFrame mainframe = new MainFrame();
        mainframe.setVisible(false);
        mainframe.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        mainframe.setSize(RTMProperties.screensize);
        mainframe.setVisible(true);
        mainframe.setDesktopBackgroundImage();
        RTMProperties.eventshistory.append(RTMProperties.time+" Creating Main Canvas \n");      
           
         }
     }
           
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         // look and feel
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        
         // Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);
        
        //properties file inlezen
      
         //starting login procedure
         //creates loginscreen
        
        JFrame owner = new JFrame("Login Dialog");
        owner.setLocation(-1000, -1000);
        owner.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        new RTMOperator(owner);
        
        
        

        /**
         LoginScreen login = new LoginScreen();
         
         //settings of the loginscreen
         login.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
         login.setAlwaysOnTop(true);
         login.setLocationRelativeTo(null);
         login.setVisible(true);
         
         userID = login.getUserID();
         */
         
         
        
        RTMProperties.eventshistory.append(RTMProperties.time+" User logged in \n");     
        MainFrame mainframe = new MainFrame();
        mainframe.setVisible(false);
        mainframe.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        mainframe.setSize(RTMProperties.screensize);
        mainframe.setVisible(true);
        mainframe.setDesktopBackgroundImage();
        RTMProperties.eventshistory.append(RTMProperties.time+" Creating Main Canvas \n");      
         }
           
        
        
        // 1) Login procedure
        // Show dialog at most three time
        // while (result == false && logincount <= 3) {
        // LoginDialog login = new LoginDialog()
        // result = login.login()
        // }
        
        // 2) open Project window
        //StartProjectScreen StartProject = new StartProjectScreen();
        //StartProject.setVisible(true);
        
        // 3) Open main window
                
       // MainFrame maincanvas = new MainFrame();
    
    public static void centerOnScreen(Window window) {
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    window.setLocation(
      (d.width - window.getSize().width) / 2,
      (d.height - window.getSize().height) / 2);
  }

       }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2006
Added on Nov 28 2006
2 comments
225 views