ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/filedialogexample.htm

189 lines
5.8 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Using IFSFileDialog" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="filedialogexample" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Using IFSFileDialog</title>
</head>
<body id="filedialogexample"><a name="filedialogexample"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using IFSFileDialog</h1>
<div><p></p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
example disclaimer</a> for important legal information.</div>
<pre>///////////////////////////////////////////////////////////////////////////////
//
// File Dialog example.
//
///////////////////////////////////////////////////////////////////////////////
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 &gt;= 1)
{
// The first parameter is the system that contains the files.
String system = parameters[0];
try
{
// Create an AS400 object for the server that contains the files.
// Connect to the file server on the server. 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 = iSeries server");
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);
}
}</pre>
</div>
</div>
</body>
</html>