Here you can find the source of stringToBounds(String str, Rectangle defaultRect)
Parameter | Description |
---|---|
str | the string in the form "x,y,w,h" |
defaultRect | the default rectangle to use if the string can't be parsed |
public static Rectangle stringToBounds(String str, Rectangle defaultRect)
//package com.java2s; import java.awt.Rectangle; public class Main { public static Rectangle stringToBounds(String str) { return stringToBounds(str, null); }/*from w ww . j av a2 s. com*/ /** * Parses the string into a Rectangle. * @param str the string in the form "x,y,w,h" * @param defaultRect the default rectangle to use if the string can't be parsed */ public static Rectangle stringToBounds(String str, Rectangle defaultRect) { Rectangle rect = defaultRect; if ((str != null) && (str.length() > 0)) { String[] xywh = str.split(","); if (xywh.length == 4) { try { Rectangle r = new Rectangle(Integer.parseInt(xywh[0]), // X Integer.parseInt(xywh[1]), // Y Integer.parseInt(xywh[2]), // WIDTH Integer.parseInt(xywh[3])); // HEIGHT rect = r; } catch (Exception ignore) { } } } return rect; } public static int parseInt(String s) { return parseInt(s, 0); } public static int parseInt(String s, int def) { int rv = def; if ((s != null) && (s.length() > 0)) { try { rv = Integer.parseInt(s); } catch (NumberFormatException ignore) { } } return rv; } }