VUserList Example
/////////////////////////////////////////////////////////////////////////
//
// VUserList example. This program presents a list of users on
// a system with a list pane and allows selection of one or more
// users.
//
// Command syntax:
// VUserListExample system
//
/////////////////////////////////////////////////////////////////////////
//
// This source is an example of AS/400 Toolbox for Java "VUserList".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// AS/400 Toolbox for Java
// (C) Copyright IBM Corp. 1997, 1998
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
/////////////////////////////////////////////////////////////////////////
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VUserListExample
{
private static AS400ListPane listPane;
public static void main (String[] args)
{
// If a system was not specified, then display help text and
// exit.
if (args.length != 1)
{
System.out.println("Usage: VUserListExample system");
return;
}
try
{
// Create an AS400 object. The system name was passed
// as the first command line argument.
AS400 system = new AS400 (args[0]);
// Create a VUserList. This represents a list of users
// for use in the list pane.
VUserList userList = new VUserList (system);
// Create a frame.
JFrame f = new JFrame ("VUserList example");
// Create an error dialog adapter. This will display
// any errors to the user.
ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (f);
// Create a list pane to display the user list.
// Use load to load the information from the system.
listPane = new AS400ListPane (userList);
listPane.addErrorListener (errorHandler);
listPane.load ();
// When the frame closes, report the selected
// users and exit.
f.addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent event)
{
reportSelectedUsers ();
System.exit (0);
}
});
// Layout the frame with the list pane.
f.getContentPane ().setLayout (new BorderLayout ());
f.getContentPane ().add ("Center", listPane);
f.pack ();
f.show ();
}
catch (Exception e)
{
System.out.println ("Error: " + e.getMessage ());
System.exit (0);
}
}
private static void reportSelectedUsers ()
{
VObject[] selectedUsers = listPane.getSelectedObjects ();
if (selectedUsers.length == 0)
System.out.println ("No users were selected.");
else
{
System.out.println ("The selected users were:");
for (int i = 0; i < selectedUsers.length; ++i)
System.out.println (selectedUsers[i]);
}
}
}