We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › instantiating objects within main
Page Index Toggle Pages: 1
instantiating objects within main (Read 1452 times)
instantiating objects within main
May 17th, 2005, 8:20pm
 
Hi all,

I'm new to the processing api so forgive this basic question.  I am trying to figure out how to instantiate objects within main from arguments passed from the command-line.  I'm building a server and want to visualize the requests.  The code I have below is how I would normally instantiate a server object in Java, but this doesn't work when I sub-class PApplet.

Any help would be appreciated.


public class MyServerVis extends PApplet
{
   public static void main(String args[]) throws IOException
   {
       if (args.length != 1)
           throw new IllegalArgumentException("Syntax:MyServerVis <port>");
       int port = Integer.parseInt(args[0]);
       ServerSocket server = new ServerSocket(port);
       while(true)
       {
           Socket client = server.accept();
           System.out.println("Accepted from " + client.getInetAddress());
           MyServer myServer = new MyServer(client);
           myServer.start();

          PApplet.main(new String[] {"--present", "--display=1", "MyServerVis"});
       }
   }
}

public class MyServer implements Runnable {
// server code here...
}
Page Index Toggle Pages: 1