Example: Using IFSFileDialog
//////////////////////////////////////////////////////////////////////////////////
//
// File Dialog example.
//
//////////////////////////////////////////////////////////////////////////////////
//
// This source is an example of IBM Toolbox for Java "FileDialog".
// 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.
//
// IBM Toolbox for Java
// (C) Copyright IBM Corp. 1997
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
//////////////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.awt.*;
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
public class FileDialogExample extends Object
{
public static void main(String[] parameters)
{
System.out.println( " " );
// if a system name was not specified, display help text and exit.
if (parameters.length >= 1)
{
// The first parameter is the system that contains the files.
String system = parameters[0];
try
{
// Create an AS400 object for the AS/400 that contains the files.
// Connect to the file server on the AS/400. Connect now so
// the sign-on screen is displayed now.
AS400 as400 = new AS400(system);
as400.connectService(AS400.FILE);
// Create a frame to hold the dialog.
Frame frame = new Frame();
// Create the file dialog object.
IFSFileDialog fileDialog = new IFSFileDialog(frame, "File Open", as400);
// Create the list of filters the user can choose then add the filters
// to the dialog.
FileFilter[] filterList = {new FileFilter("All files (*.*)", "*.*"),
new FileFilter("Executables (*.exe)", "*.exe"),
new FileFilter("HTML files (*.html)", "*.html"),
new FileFilter("Images (*.gif)", "*.gif"),
new FileFilter("Text files (*.txt)", "*.txt")};
fileDialog.setFileFilter(filterList, 0);
// Set the text for the "OK" button on the dialog.
fileDialog.setOkButtonText("Open");
// Set the text for the "Cancel" button on the dialog.
fileDialog.setCancelButtonText("Cancel");
// Set the initial directory for the dialog.
fileDialog.setDirectory("/");
// Display the dialog and wait until the user presses OK or Cancel
int pressed = fileDialog.showDialog();
// If the user pressed OK, get the fully qualified path and name
// of the file they chose.
if (pressed == IFSFileDialog.OK)
{
System.out.println("User selected: " + fileDialog.getAbsolutePath());
}
// Else if the user pressed cancel, display a message.
else if (pressed == IFSFileDialog.CANCEL)
{
System.out.println("User pressed cancel");
}
else
System.out.println("User didn't press Open or Cancel");
}
catch(Exception e)
{
// If any of the above operations failed say the dialog operation
// failed and output the exception.
System.out.println("Dialog operation failed");
System.out.println(e);
}
}
// Display help text when parameters are incorrect.
else
{
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("Parameters are not correct. Command syntax is:");
System.out.println("");
System.out.println(" FileDialogExample system");
System.out.println("");
System.out.println("Where");
System.out.println("");
System.out.println(" system = AS/400");
System.out.println("");
System.out.println("For example:");
System.out.println("");
System.out.println("");
System.out.println(" FileDialogExample mySystem");
System.out.println("");
System.out.println("");
}
System.exit(0);
}
}