Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Login Dialog box using frames...

Posted on 2002-03-25
7
Medium Priority
?
384 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
Independent Software Vendors: 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

636 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