Solved

Login Dialog box using frames...

Posted on 2002-03-25
7
365 Views
Last Modified: 2010-03-31
can somebody provide me the sample code for login dialog box using frames.i want both the dialog box and the listener action as well i,e capturing the user name and password .Also how to show a message in the same dialog box if the user leaves one of the fields blank.
0
Comment
Question by:anuj_roy
7 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6894503
try this
0
 
LVL 9

Expert Comment

by:Venci75
ID: 6894505
import java.awt.*;
import java.awt.event.*;
import com.borland.jbcl.layout.*;
public class LoginBox extends Frame {
  Label message = new Label();
  TextField user = new TextField();
  XYLayout xYLayout1 = new XYLayout();
  TextField pwd = new TextField();
  Button ok = new Button();
  Button cancel = new Button();

  public LoginBox() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  private void jbInit() throws Exception {
    message.setText("Enter username/password");
    this.setLayout(xYLayout1);
    ok.setLabel("ok");
    ok.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ok_actionPerformed(e);
      }
    });
    cancel.setLabel("cancel");
    cancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        cancel_actionPerformed(e);
      }
    });
    pwd.setEchoChar('*');
    this.add(user,    new XYConstraints(38, 39, 151, -1));
    this.add(message,  new XYConstraints(37, 8, 180, -1));
    this.add(pwd,  new XYConstraints(38, 68, 151, -1));
    this.add(ok,   new XYConstraints(35, 98, 67, -1));
    this.add(cancel,   new XYConstraints(118, 98, -1, -1));
  }
  void ok_actionPerformed(ActionEvent e) {
      if (user.getText() == null || user.getText().length() == 0) {
          message.setText("The user field is empty");
          return;
      }
      if (pwd.getText() == null || pwd.getText().length() == 0) {
          message.setText("The password field is empty");
          return;
      }
      this.hide();
  }

  void cancel_actionPerformed(ActionEvent e) {
      this.hide();
  }
}
0
 

Author Comment

by:anuj_roy
ID: 6895637
thanx venci for u'r reply but i want to use the dialogbox class for the problem.can u provide the code for the same using jdialogbox
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:s_lavie
ID: 6895934
Homework???
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 125 total points
ID: 6896067
import javax.swing.*;
import javax.swing.event.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
public class LoginBox extends JFrame {
  JLabel message = new JLabel();
  JTextField user = new JTextField();
  XYLayout xYLayout1 = new XYLayout();
  JPasswordField pwd = new JPasswordField();
  JButton ok = new JButton();
  JButton cancel = new JButton();

  public LoginBox() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  private void jbInit() throws Exception {
    message.setText("Enter username/password");
    this.getContentPane().setLayout(xYLayout1);
    ok.setLabel("ok");
    ok.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ok_actionPerformed(e);
      }
    });
    ok.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ok_actionPerformed(e);
      }
    });
    cancel.setLabel("cancel");
    cancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        cancel_actionPerformed(e);
      }
    });
//    pwd.setEchoChar('*');
    this.getContentPane().add(user,    new XYConstraints(38, 39, 151, -1));
    this.getContentPane().add(message,  new XYConstraints(37, 8, 180, -1));
    this.getContentPane().add(pwd,  new XYConstraints(38, 68, 151, -1));
    this.getContentPane().add(ok,   new XYConstraints(35, 98, 67, -1));
    this.getContentPane().add(cancel,   new XYConstraints(118, 98, -1, -1));
  }

  void ok_actionPerformed(ActionEvent e) {
      if (user.getText() == null || user.getText().length() == 0) {
          message.setText("The user field is empty");
          return;
      }
      if (pwd.getText() == null || pwd.getText().length() == 0) {
          message.setText("The password field is empty");
          return;
      }
      this.hide();
  }

  void cancel_actionPerformed(ActionEvent e) {
      this.hide();
  }
}
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7892617
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: Venci75
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7962530
Per recommendation, force-accepted.

Netminder
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 77
groupNoAdj 7 86
Exception after setting jdbc session management 2 52
Non-recursive backtracking, using a stack 1 102
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now