Java Rectangle Create Parse stringToRectangle(String s, Rectangle defaultValue)

Here you can find the source of stringToRectangle(String s, Rectangle defaultValue)

Description

string To Rectangle

License

Open Source License

Declaration

public static Rectangle stringToRectangle(String s, Rectangle defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Rectangle;

public class Main {
    public static Rectangle stringToRectangle(String s, Rectangle defaultValue) {
        if (s == null)
            return defaultValue;
        String[] sa = s.split(" +");
        if (sa.length != 4)
            return defaultValue;
        int[] ia = new int[4];
        for (int i = 0; i < 4; i++)
            try {
                ia[i] = Integer.parseInt(sa[i]);
            } catch (NumberFormatException e) {
                return defaultValue;
            }/* ww  w  . ja  v a  2  s.c o  m*/
        return new Rectangle(ia[0], ia[1], ia[2], ia[3]);
    }
}

Related

  1. rectangleToString(Rectangle r)
  2. rectangleToString(Rectangle rectangle)
  3. storeBounds(String name, Window window)
  4. stringToBounds(String str, Rectangle defaultRect)
  5. stringToRectangle(String s)
  6. stringToRectangle(String str)
  7. stringToRectangle(String string, Rectangle defaultValue)
  8. stringToRectangle(String value)