Solved

Login Dialog box using frames...

Posted on 2002-03-25
7
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaFX TableView not displaying correctly 3 105
jmss example java 2 32
add projects t working set in maven 2 40
spring maven example issues 3 40
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

756 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