public void run() {
    try {
      while (true) {
        String message = in.readLine();

        if (message.equals("mousePressed")) {
          try {
            String x = in.readLine();
            String y = in.readLine();
            String flag = in.readLine();
            String re = in.readLine();
            String gree = in.readLine();
            String blac = in.readLine();
            String size = in.readLine();
            int x_ = Integer.parseInt(x);
            int y_ = Integer.parseInt(y);
            int red = Integer.parseInt(re);
            int green = Integer.parseInt(gree);
            int black = Integer.parseInt(blac);
            flagtool = Integer.parseInt(flag);
            border = Integer.parseInt(size);
            flagcolor = new Color(red, green, black);
            onePoint pp1 = new onePoint(x_, y_, flagtool, flagcolor, border);
            points.add(pp1);
            repaint();
          } catch (Exception ex) {
            ex.getSuppressed();
          }
        } else if (message.equals("mouseReleased")) {
          String isPen = in.readLine();
          if (isPen.equals("isPen")) {
            if (isEraser == 0) points.addElement(new onePoint(-1, -1, 22, flagcolor, border));
            else if (isEraser == 1) points.addElement(new onePoint(-1, -1, 22, Color.WHITE, 6 * 2));
          } else {
            String x = in.readLine();
            String y = in.readLine();
            String flag = in.readLine();
            String re = in.readLine();
            String gree = in.readLine();
            String blac = in.readLine();
            String size = in.readLine();
            try {
              int x_ = Integer.parseInt(x);
              int y_ = Integer.parseInt(y);
              int red = Integer.parseInt(re);
              int green = Integer.parseInt(gree);
              int black = Integer.parseInt(blac);
              flagtool = Integer.parseInt(flag);
              border = Integer.parseInt(size);
              flagcolor = new Color(red, green, black);
              onePoint pp1 = new onePoint(x_, y_, flagtool, flagcolor, border);
              points.addElement(pp1);
              points.add(new onePoint(-1, -1, 22, flagcolor, border));
              repaint();
            } catch (NumberFormatException e) {
              e.getSuppressed();
            }
          }
        } else if (message.equals("itemStateChanged")) {
          String item = in.readLine();
          if (item.equals("colorchoice")) {
            String color = in.readLine();
            if (color.equals("black")) flagcolor = new Color(0, 0, 0);
            else if (color.equals("red")) flagcolor = new Color(255, 0, 0);
            else if (color.equals("blue")) flagcolor = new Color(0, 0, 255);
            else if (color.equals("green")) flagcolor = new Color(0, 255, 0);

          } else if (item.equals("sizechoice")) {
            String size = in.readLine();
            if (size.equals("1")) {
              border = 1;
            } else if (size.equals("2")) border = 2 * 2;
            else if (size.equals("4")) border = 4 * 2;
            else if (size.equals("6")) border = 6 * 2;
            else if (size.equals("8")) border = 8 * 2;
          }
        } else if (message.equals("actionPerformed")) {
          String ispen = in.readLine();
          if (ispen.equals("pen")) {
            flagtool = 0;
            isEraser = 0;
          } else if (ispen.equals("line")) {
            flagtool = 1;
          } else if (ispen.equals("clear")) {
            flagtool = 2;
            points.removeAllElements();
            repaint();
          } else if (ispen.equals("ellipse")) {
            flagtool = 3;
          } else if (ispen.equals("rect")) {
            flagtool = 4;
          } else if (ispen.equals("colorboard")) {
            try {
              String red = in.readLine();
              String green = in.readLine();
              String blue = in.readLine();
              flagcolor =
                  new Color(Integer.parseInt(red), Integer.parseInt(green), Integer.parseInt(blue));

            } catch (Exception e) {
              e.getSuppressed();
            }
          } else if (ispen.equals("eraser")) {
            flagtool = 0;
            isEraser = 1;
          }
        } else if (message.equals("mouseDragged")) {
          String a = in.readLine();
          if (a.equals("0")) {
            try {
              String x = in.readLine();
              String y = in.readLine();
              String flag = in.readLine();
              String red = in.readLine();
              String green = in.readLine();
              String blue = in.readLine();
              String bord = in.readLine();
              int x_ = Integer.parseInt(x);
              int y_ = Integer.parseInt(y);
              flagtool = Integer.parseInt(flag);
              flagcolor =
                  new Color(Integer.parseInt(red), Integer.parseInt(green), Integer.parseInt(blue));
              border = Integer.parseInt(bord);
              onePoint pp = new onePoint(x_, y_, flagtool, flagcolor, border);
              points.addElement(pp);
              repaint();
            } catch (Exception e) {
              e.getSuppressed();
            }
          } else if (a.equals("1")) {
            try {
              String x = in.readLine();
              String y = in.readLine();
              String flag = in.readLine();
              String red = in.readLine();
              String green = in.readLine();
              String blue = in.readLine();
              String bord = in.readLine();
              int x_ = Integer.parseInt(x);
              int y_ = Integer.parseInt(y);
              flagtool = Integer.parseInt(flag);
              flagcolor =
                  new Color(Integer.parseInt(red), Integer.parseInt(green), Integer.parseInt(blue));
              border = Integer.parseInt(bord);
              onePoint pp = new onePoint(x_, y_, flagtool, flagcolor, border);
              points.add(pp);
              repaint();
            } catch (Exception e) {
              e.getSuppressed();
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
 private static int getIntSystemProperty(final int defaultValue, final String key) {
   try {
     return Integer.parseInt(System.getProperty(key, "" + defaultValue));
   } catch (NumberFormatException e) {
     LOG.error(BUNDLE_MARKER, e.toString(), e);
   }
   return defaultValue;
 }
Ejemplo n.º 3
0
  public static void main(String args[]) {
    int port;
    String host;

    if (args.length == 1) {
      try {
        port = Integer.parseInt(args[0]);

        doEcho(port);

      } catch (IOException io_ex) {
        io_ex.printStackTrace();
        System.exit(1);

      } catch (NumberFormatException num_ex) {
        num_ex.printStackTrace();
        System.exit(1);
      }
    } else if (args.length == 2) {
      try {
        host = args[0];
        port = Integer.parseInt(args[1]);

        UDPEcho ut = new UDPEcho(host, port);
        Thread thread = new Thread(ut);
        thread.start();

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s;
        System.out.print("Enter datagram:");
        s = in.readLine();
        while (s != null) {
          ut.send(s);
          try {
            Thread.currentThread().sleep(100);
          } catch (InterruptedException i_ex) {
          }
          System.out.print("Enter datagram:");
          s = in.readLine();
        }
        System.exit(1);

      } catch (IOException io_ex) {
        io_ex.printStackTrace();
        System.exit(1);
      } catch (NumberFormatException num_ex) {
        num_ex.printStackTrace();
        System.exit(1);
      }

    } else {
      usage();
    }
  }
  /**
   * This method gets called when a property we're interested in is about to change. In case we
   * don't like the new value we throw a PropertyVetoException to prevent the actual change from
   * happening.
   *
   * @param evt a <tt>PropertyChangeEvent</tt> object describing the event source and the property
   *     that will change.
   * @exception PropertyVetoException if we don't want the change to happen.
   */
  public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
    if (evt.getPropertyName().equals(PROP_STUN_SERVER_ADDRESS)) {
      // make sure that we have a valid fqdn or ip address.

      // null or empty port is ok since it implies turning STUN off.
      if (evt.getNewValue() == null) return;

      String host = evt.getNewValue().toString();
      if (host.trim().length() == 0) return;

      boolean ipv6Expected = false;
      if (host.charAt(0) == '[') {
        // This is supposed to be an IPv6 litteral
        if (host.length() > 2 && host.charAt(host.length() - 1) == ']') {
          host = host.substring(1, host.length() - 1);
          ipv6Expected = true;
        } else {
          // This was supposed to be a IPv6 address, but it's not!
          throw new PropertyVetoException("Invalid address string" + host, evt);
        }
      }

      for (int i = 0; i < host.length(); i++) {
        char c = host.charAt(i);
        if (Character.isLetterOrDigit(c)) continue;

        if ((c != '.' && c != ':') || (c == '.' && ipv6Expected) || (c == ':' && !ipv6Expected))
          throw new PropertyVetoException(host + " is not a valid address nor host name", evt);
      }

    } // is prop_stun_server_address
    else if (evt.getPropertyName().equals(PROP_STUN_SERVER_PORT)) {

      // null or empty port is ok since it implies turning STUN off.
      if (evt.getNewValue() == null) return;

      String port = evt.getNewValue().toString();
      if (port.trim().length() == 0) return;

      try {
        Integer.valueOf(evt.getNewValue().toString());
      } catch (NumberFormatException ex) {
        throw new PropertyVetoException(port + " is not a valid port! " + ex.getMessage(), evt);
      }
    }
  }
Ejemplo n.º 5
0
 private static byte[] getFourByteSystemProperty(final byte[] defaultValue, final String key) {
   final String address = System.getProperty(key);
   if (address == null) {
     return defaultValue;
   }
   try {
     final String[] byteStrings = address.split("\\.");
     if (byteStrings.length != 4) {
       return defaultValue;
     }
     final byte[] bytes = new byte[4];
     for (int i = 0; i < bytes.length; i++) {
       bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
     }
     return bytes;
   } catch (NumberFormatException e) {
     LOG.error(BUNDLE_MARKER, e.toString(), e);
   }
   return defaultValue;
 }
Ejemplo n.º 6
0
  public VirtualMachine attach(Map arguments)
      throws IOException, IllegalConnectorArgumentsException {
    int pid = 0;
    try {
      pid = Integer.parseInt(argument(ARG_PID, arguments).value());
    } catch (NumberFormatException nfe) {
      throw (IllegalConnectorArgumentsException)
          new IllegalConnectorArgumentsException(nfe.getMessage(), ARG_PID).initCause(nfe);
    }

    checkProcessAttach(pid);

    VirtualMachine myVM = null;
    try {
      try {
        Class vmImplClass = loadVirtualMachineImplClass();
        myVM = createVirtualMachine(vmImplClass, pid);
      } catch (InvocationTargetException ite) {
        Class vmImplClass = handleVMVersionMismatch(ite);
        if (vmImplClass != null) {
          return createVirtualMachine(vmImplClass, pid);
        } else {
          throw ite;
        }
      }
    } catch (Exception ee) {
      if (DEBUG) {
        System.out.println("VirtualMachineImpl() got an exception:");
        ee.printStackTrace();
        System.out.println("pid = " + pid);
      }
      throw (IOException) new IOException().initCause(ee);
    }
    setVMDisposeObserver(myVM);
    return myVM;
  }