import java.awt.BorderLayout; import java.net.InetAddress; import java.net.UnknownHostException; import javax.swing.JFrame; /** * * @author emi-lind * */ public class UniDraw extends JFrame { private final static int DEFAULT_LOCAL_PORT = 2000; private final static String DEFAULT_HOST = "localhost"; private final static int DEFAULT_REMOTE_PORT = 2001; private int _localPort; private InetAddress _host; private int _remotePort; public static void main (String[] args) { new UniDraw(args); } public UniDraw(String[] aArgs) { super("Unicast Draw v1.0"); this.readArgs(aArgs); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new UniPaper(this), BorderLayout.CENTER); setSize(800, 400); setVisible(true); } private void readArgs(String[] aArgs) { _localPort = DEFAULT_LOCAL_PORT; _remotePort = DEFAULT_REMOTE_PORT; String tmpHost = DEFAULT_HOST; if (aArgs.length == 3) { tmpHost = aArgs[1]; try { _localPort = Integer.parseInt(aArgs[0]); _remotePort = Integer.parseInt(aArgs[2]); } catch (NumberFormatException e) { System.err.println("Invalid port(s)! Error: " + e); System.exit(1); } } try { _host = InetAddress.getByName(tmpHost); } catch (UnknownHostException e) { System.err.println(e); } System.out.println("Using:\nLocal Port: \t" + _localPort + "\nRemote Host: \t" + _host + "\nRemote Port: \t" + _remotePort); } public int getLocalPort() { return _localPort; } public InetAddress getRemoteHost() { return _host; } public int getRemotePort() { return _remotePort; } }