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

146 lines
5.5 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?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 CommandCallMenuItem" />
<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="commandcallmenuitemexample" />
<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 CommandCallMenuItem</title>
</head>
<body id="commandcallmenuitemexample"><a name="commandcallmenuitemexample"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using CommandCallMenuItem</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>/////////////////////////////////////////////////////////////////////////
//
// Command call menu item example. This program demonstrates how to
// use a menu item that calls a server command. It will display
// any messages that are returned in a dialog.
//
// Command syntax:
// CommandCallMenuItemExample system
//
/////////////////////////////////////////////////////////////////////////
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CommandCallMenuItemExample
{
private static JFrame f;
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: CommandCallMenuItemExample 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 frame.
f = new JFrame ("Command call menu item example"
// Create an error dialog adapter. This will display
// any errors to the user.
ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (f);
// Create a CommandCallMenuItem object to run the command.
CommandCallMenuItem menuItem =
new CommandCallMenuItem ("Clear library FRED", null, system, "CLRLIB FRED");
menuItem.addErrorListener (errorHandler);
// Add an action completed listener to display any
// returned messages in a dialog.
menuItem.addActionCompletedListener (new ActionCompletedListener ()
{
public void actionCompleted (ActionCompletedEvent event)
{
// Get the message list from the event source.
CommandCallMenuItem item = (CommandCallMenuItem) event.getSource ();
AS400Message[] messageList = item.getMessageList ();
// Use an AS400DetailsPane to display the messages.
VMessageList vmessageList = new VMessageList (messageList);
AS400DetailsPane messageDetails = new AS400DetailsPane (vmessageList);
messageDetails.load ();
// Show the details in a dialog.
JDialog dialog = new JDialog(f);
dialog.getContentPane().setLayout(new BorderLayout());
dialog.getContentPane().add("Center"messageDetails);
dialog.pack();
dialog.setVisible(true);
}
});
// Create a menu with the item.
JMenu menu = new JMenu ("Server Command Calls");
menu.add (menuItem);
JMenuBar menuBar = new JMenuBar ();
menuBar.add (menu);
f.getRootPane ().setJMenuBar (menuBar);
// When the frame closes, exit.
f.addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent event)
{
System.exit (0);
}
});
// Layout the frame with the details pane.
f.getContentPane ().setLayout (new BorderLayout ());
f.setSize (300, 400);
f.show ();
}
catch (Exception e)
{
System.out.println ("Error: " + e.getMessage ());
System.exit (0);
}
}
}</pre>
</div>
</div>
</body>
</html>