This example program uses the CommandPrompter, CommandCall, and AS400Message classes to prompt for a command, run the command, and display any messages returned if the command does not run.
//////////////////////////////////////////////////////////////////////////////////
//
// CommandPrompter example. This program uses CommandPrompter, CommandCall, and
// AS400Message to prompt for a command, run the command, and display any
// messages returned if the command does not run.
//
// Command syntax:
// Prompter commandString
//
//////////////////////////////////////////////////////////////////////////////////
import com.ibm.as400.ui.util.CommandPrompter;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.CommandCall;
import javax.swing.JFrame;
import java.awt.FlowLayout;
public class Prompter
{
public static void main ( String args[] ) throws Exception
{
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
AS400 system = new AS400("mySystem", "myUserId", "myPasswd");
String cmdName = args[0];
// Launch the CommandPrompter
CommandPrompter cp = new CommandPrompter(frame, system, cmdName);
if (cp.showDialog() == CommandPrompter.OK)
{
String cmdString = cp.getCommandString();
System.out.println("Command string: " + cmdString);
// Run the command that was built in the prompter.
CommandCall cmd = new CommandCall(system, cmdString);
if (!cmd.run())
{
AS400Message[] msgList = cmd.getMessageList();
for (int i = 0; i < msgList.length; ++i)
{
System.out.println(msgList[i].getText());
}
}
}
System.exit(0);
}
}