Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
package com.ptc.jlinkasyncexamples;
import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcAsyncConnection.*;
import com.ptc.pfc.pfcExceptions.*;
/**
* This asynchronous class is a fully asynchronous application. It follows
* the procedure for a full asynchronous application:
* 1.) the application establishes listeners for Pro/ENGINEER events (in
* this case, the menu button and the termination listener)
* 2.) the application goes into a control loop calling EventProcess()
* which allows the application to respond to the Pro/ENGINEER events.
*/
public class pfcAsyncFullExample extends AsyncActionListener_u
{
private AsyncConnection connection;
private boolean exit_flag = false;
public static void main (String [] args) throws com.ptc.cipjava.jxthrowable
{
if (args.length != 2)
{
printMsg ("Incorrect argument list.");
printMsg ("Arguments: java com.ptc.jlinkasyncexamples.pfcAsyncFullExample <pro/E command> <text path>");
return;
}
try
{
System.loadLibrary ("jotkasync");
}
catch (UnsatisfiedLinkError error)
{
printMsg ("Could not load J-Link library pfcasyncmt.");
return;
}
new pfcAsyncFullExample (args);
}
// Constructor
private pfcAsyncFullExample (String args[]) throws com.ptc.cipjava.jxthrowable
{
startProE (args);
addTerminationListener ();
addMenuButton();
while (!exit_flag)
{
// Could do other regualar processing here, but the EventProcess()
// calls should happen regularly, so that Pro/ENGINEER does not
// appear slow in responding to menu button picks
try
{
connection.EventProcess ();
Thread.sleep (100);
}
catch (java.lang.InterruptedException ex)
{
}
}
// Wait here a bit so Pro/ENGINEER can finish shutting down.
try
{
Thread.sleep (2000);
connection.EventProcess ();
}
catch (java.lang.InterruptedException ex)
{
}
}
/**
* Starts Pro/ENGINEER.
*/
void startProE (String[] args) throws com.ptc.cipjava.jxthrowable
{
try
{
// args[0] = Pro/ENGINEER command
// args[1] = text path for menu/message files
connection = pfcAsyncConnection.AsyncConnection_Start (args [0], args[1]);
}
catch (XToolkitGeneralError error)
{
printMsg ("Could not start Pro/ENGINEER.");
System.exit (0);
}
return;
}
/**
* Adds a menu and a menu button to the Pro/E menubar.
*/
void addMenuButton () throws com.ptc.cipjava.jxthrowable
{
Session s = connection.GetSession ();
UICommand cmd = s.UICreateCommand ( "AsyncCommand", (UICommandActionListener) new ButtonListener());
s.UIAddMenu ("J-Link", "Applications", "menu_text.txt", null);
s.UIAddButton (cmd, "J-Link", null, "AsyncApp", "AsyncAppHelp", "menu_text.txt");
}
/**
* Adds a handler for Pro/ENGINEER's exit.
*/
void addTerminationListener () throws com.ptc.cipjava.jxthrowable
{
connection.AddActionListener ((AsyncActionListener)this);
printMsg ("Termination listener added.");
}
/**
* Termination handler - from the AsyncActionListener interface.
*/
public void OnTerminate (TerminationStatus status)
{
printMsg ("Pro/ENGINEER shutting down.");
exit_flag = true;
}
public static void printMsg (String msg)
{
System.out.println (msg);
}
}
class ButtonListener extends DefaultUICommandActionListener
{
/**
* Menu button action - from interface UICommandActionListener
*/
public void OnCommand ()
{
pfcAsyncFullExample.printMsg ("User menu button pushed.");
}
}
Hi,
1. What version of the program are you using?
2. What were you doing before this error appeared? More details are needed.
Basically I started working on CREO Jlink, i am using creo 5.0 and have only resource is its PTC pdf, I ruined install test. and now i am try to run pfcAsyncFullExample, i don't no how to run this example, if i just run that example in IDE , its showing main class is not loading or not there.
There is no complete step on how to run example files in that PTC pdf.
Can u help me on that...
Read the following articles:
what arguments do you pass to main method ?