× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: AS400 Connection Listener
  • From: "Padmanabhan R (RBIN/ACF)" <Padmanabhan.R@xxxxxxxxxxxx>
  • Date: Sat, 3 Jun 2000 14:05:32 +0200

 Hello Every Body , 

                I have written a Login screen for AS/400 with Grid Layout
Constraints. I am not able to proceed after one step. I am new to Java
programming so please help me in completing the following code. The basic
requirement is it should connect to the as400 when accessing from the we
browser. I was able to complete till the connection. This code will prompt
for a login using Dialog box. 
My requirements  are  
1.      Since it will take some time to connect to the as400 , so during
that time I want to activate a progress bar , but not able to accomplish
that. 
2.      I am not able to throw as400 connection event by which I thought I
can activate. 
3.      It is working fine other wise. 
4.      How to trap the connection event and implement 
5.      How to activate a progress bar. 
6.      Please give me suggestions to improve my coding techniques. 
7.      How to retrieve a flag such that , the NET.data macro from which I
am calling this applet realizes that the connection has been established. 

My main program 

/***************************************************************************
*******************/
/* Program Name      :  login.java
*/
/*
*/
/* Description       :  Java Applet Program  that receives the UserId &
Password             */
/*                      and performs the Validations
*/          
/*
*/ 
/* Referenced Classes : screen
*/
/***************************************************************************
*******************/

 import com.ibm.as400.access.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.io.*;
 import java.applet.*;
 import javax.swing.*;  

public class AS400login extends Applet
 {

           
        public void init(){
                        
            LoginDialog as400signon = new LoginDialog();
                                as400signon.setResizable(false);
                                as400signon.show();
                                                                        
        }
        
        public  static void main(String args[]){
                        
            LoginDialog as400signon = new LoginDialog();
                        as400signon.setResizable(false);
                                as400signon.show();
                                                                        
        }

 

}


class LoginDialog extends Dialog
{

        Button Signon = new Button("Signon");
  Button Cancel  = new Button("Cancel");
  TextField SignonSystem = new TextField("MICO11",10);
  TextField User = new TextField(10);
  TextField Password = new TextField(10);
        Label SystemName = new Label("System  ");
        Label UserName  = new Label("User    ");        
        Label PasswordEntry = new Label("Password");
        Label Blank  = new Label("Connecting to MICO11");
  AS400 as400 = new AS400("" ,"" , "" );
  int rcode=0;  
        //Progress Bar Simulation. 
        JProgressBar pbar = new JProgressBar(JProgressBar.HORIZONTAL);

        
        
        char EchoChar = '*';
        Panel p0 = new Panel();
        Panel p1 = new Panel();
        Panel p2 = new Panel();
    
        
        BorderLayout borderlayout = new BorderLayout();
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c1 = new GridBagConstraints();
        GridBagConstraints c2 = new GridBagConstraints();
         


        public LoginDialog ()
  {

        //For Creating a Dialog Box Frame 
        
        super(new Frame("AS/400 Signon Frame") ,"AS4/00 Signon Prompt", true
);
        this.setLayout(borderlayout);
        resize(300,250);
        move(240,240);
  
        //to add the action Listeners. 
  addWindowListener(new WindowEventHandler());  
  Signon.addActionListener(new HandleButton()); 
  Cancel.addActionListener(new HandleButton()); 
        as400.addConnectionListener(new as400ConnectionEvent());
        
  borderlayout.setVgap(5);      
        
  // Add the  panels to the frame.      
  add(p0,BorderLayout.NORTH); // Image Panel
        add(p1,BorderLayout.CENTER); // Field Panel
  add(p2,BorderLayout.SOUTH); //Button Panel 
        
        
        //The Intial Prompt Screen Intialisation
        Password.setEchoChar(EchoChar);
  Blank.disable();
  pbar.disable();       
  SignonSystem.setEditable(false);
  SystemName.setFont(new java.awt.Font("dialog",1,12)); 
        UserName.setFont(new java.awt.Font("dialog",1,12));     
  PasswordEntry.setFont(new java.awt.Font("dialog",1,12));
  SystemName.setAlignment(java.awt.Label.LEFT);
  UserName.setAlignment(java.awt.Label.LEFT);
  PasswordEntry.setAlignment(java.awt.Label.LEFT);      
  User.requestFocus();  
  
        //creating a panel for arangement of the 
  p0.setLayout(gridbag);        
  p1.setLayout(gridbag);
  p2.setLayout(gridbag);
          
  p0.add(Blank);
  //changing the relative positions. 
    c1.weightx = 1.0;
        c1.gridwidth = GridBagConstraints.RELATIVE;
    gridbag.setConstraints(SystemName, c1);     
        p1.add(SystemName);
        
    c1.gridwidth = GridBagConstraints.REMAINDER;        
        gridbag.setConstraints(SignonSystem, c1);       
                p1.add(SignonSystem);
   
    c1.weighty = 1.0;
        c1.gridwidth = GridBagConstraints.RELATIVE;     
    gridbag.setConstraints(UserName, c1);       
        p1.add(UserName);

                c1.gridwidth = GridBagConstraints.REMAINDER;    
    gridbag.setConstraints(User, c1);   
        p1.add(User);
        
        c1.weighty = 0.5;
        c1.weightx = 0.0;
        c1.gridwidth = GridBagConstraints.RELATIVE;
        gridbag.setConstraints(PasswordEntry, c1);
        p1.add(PasswordEntry);
        
                c1.gridwidth = GridBagConstraints.REMAINDER;
        gridbag.setConstraints(Password, c1);
    p1.add(Password);
        
        c2.weighty = 0.0;
        c2.weightx = 0.5;
        c2.gridwidth = GridBagConstraints.RELATIVE;
    gridbag.setConstraints(Signon, c2);
    p2.add(Signon);
        
  
        c2.gridwidth = GridBagConstraints.REMAINDER;
        gridbag.setConstraints(Cancel, c2);
          p2.add(Cancel);

        c2.weighty = 1.0;
        c2.weightx = 1.0;
        c2.gridwidth = GridBagConstraints.CENTER;
        gridbag.setConstraints(Blank,c2);
        p2.add(Blank);
        
        c2.weighty = 1.0;
        c2.gridwidth = GridBagConstraints.CENTER;
        gridbag.setConstraints(pbar,c2);
        p2.add(pbar);
 
        
}
 
        class HandleButton implements ActionListener {
  // Handle the clicking of a button
  public void actionPerformed(ActionEvent ev){
  String s=ev.getActionCommand();
  if (s.equals("Signon"))
        {
          if(User.getText().length() == 0)
                {
                        String ErrorMessage = "User Field cannot be blanks";
      OKDialog myDialog = new OKDialog(ErrorMessage);
                        myDialog.setResizable(false);
      myDialog.show();
                        User.requestFocus();
                        return ;        
                }
                
                
                if(Password.getText().length() == 0)
                {
                        String ErrorMessage = "Password Field cannot be
blanks";
      OKDialog myDialog = new OKDialog(ErrorMessage);
                        myDialog.setResizable(false);
      myDialog.show();
                        Password.requestFocus();
                        return ;        
                }
        }

        if (s.equals("Cancel"))
        {
   dispose();
         return;
        }       
        
        try{
/***************************************************************************
*******************/
/*      AS400 Connecting routine
*/             
/***************************************************************************
*******************/
        as400.disconnectAllServices();  
        as400 = new com.ibm.as400.access.AS400(SignonSystem.getText()
,User.getText(),Password.getText());
  as400.setGuiAvailable(false);
  if(as400.validateSignon(User.getText(),Password.getText()))
    {
   
        String ErrorMessage = "Good Connected";
      OKDialog myDialog = new OKDialog(ErrorMessage);
                        myDialog.setResizable(false);
      myDialog.show();
                        Password.requestFocus();
        Signon.disable();
      Blank.disable();
      pbar.disable();   

                        return ;
    }
                        
  }
    catch(AS400SecurityException e)
    {          

/***************************************************************************
*******************/
/*      Displaying   error messges
*/             
/***************************************************************************
*******************/
     rcode = e.getReturnCode();
    if(rcode == AS400SecurityException.USERID_UNKNOWN)
     {
      String ErrorMessage = "Invalid User Profile";
      OKDialog myDialog = new OKDialog(ErrorMessage);
                        myDialog.setResizable(false);
      myDialog.show();
        Signon.enable();
          Blank.disable();
      pbar.disable();   
        User.requestFocus();
        return ;
     }
   else
    if(rcode == AS400SecurityException.PASSWORD_INCORRECT)
     {
      String ErrorMessage = "Password not Valid";
      OKDialog myDialog = new OKDialog(ErrorMessage);
                        myDialog.setResizable(false);
      myDialog.show();
        Signon.enable();
          Blank.disable();
      pbar.disable();   
        Password.requestFocus();
        return ;

     }
   else
    {
      String ErrorMessage = "Error -Contact System Admin";
      OKDialog myDialog = new OKDialog(ErrorMessage);
                        myDialog.setResizable(false);
      myDialog.show();
        Signon.enable();
          Blank.disable();
      pbar.disable();   
        User.requestFocus();
                        return ;

     }
    
                        
    }
        
        catch(java.beans.PropertyVetoException ve){}
    
        catch(IOException ie){}

  }
 }



class as400ConnectionEvent implements ConnectionListener
{
        
        public void connected(ConnectionEvent e)
        {
  Signon.disable();
  Blank.enable();
  pbar.enable();        

         }
        public void disconnected(ConnectionEvent e)
        {
        
        String ErrorMessage = "Good disConnected";
      OKDialog myDialog = new OKDialog(ErrorMessage);
                        myDialog.setResizable(false);
      myDialog.show();

         }

                
        }


}

class WindowEventHandler extends WindowAdapter {
  // Handle the window's closing
 public void windowClosing(WindowEvent e){
  System.exit(0);
  }
}



/***********************  End Of The Program
***************************************************/

Dialog Box Class 

import java.applet.Applet;
import java.awt.Dialog; 
import java.awt.Frame;
import java.awt.Button;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Event;
import java.awt.BorderLayout;


public class OKDialog extends Dialog {

  Button OK = new Button("OK");
        
  public OKDialog(String ErrorMessage) {
        super(new Frame("Error Message" ) ,"Error Message", true );
        addWindowListener(new WindowEventHandler());
        BorderLayout borderlayout = new BorderLayout();
    this.setLayout(borderlayout);
        Label Blank = new Label(ErrorMessage);
        Blank.setAlignment(Label.CENTER);
        Blank.setBackground(new java.awt.Color(179,209,220));
    resize(275, 150);
    move(300,300);
    Panel p1 = new Panel();
    p1.setLayout(null);
        Blank.setBounds(25,25,225,40);
        OK.setBounds(125,75,25,25);
        p1.add(Blank);
    p1.add(OK);
    add(p1,BorderLayout.CENTER);
  }

  public boolean action(Event e, Object o) {
  
    if (e.target == OK) {
      dispose();
      return true;
    }
    return false;
  
  }

}


Please help me. 

With regards

Padmanabhan
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.