Solved

Login Dialog box using frames...

Posted on 2002-03-25
7
362 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
nestparen challenge 4 57
mapAB Challlenge 35 89
java set up 1 48
Java Message handling in Service Layer 3 38
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

747 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

16 Experts available now in Live!

Get 1:1 Help Now