Java Rectangle Create Parse rectangleToString(Rectangle rectangle)

Here you can find the source of rectangleToString(Rectangle rectangle)

Description

Convert a Rectangle object to a comma separated string in the format of x,y,width,height.

License

Open Source License

Parameter

Parameter Description
rectangle rectangle

Return

comman separated string x,y,width,height

Declaration

public static String rectangleToString(Rectangle rectangle) 

Method Source Code

//package com.java2s;
/*//w w w  .  j a  va2  s .  co  m
*  Adito
*
*  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
*  This program is free software; you can redistribute it and/or
*  modify it under the terms of the GNU General Public License
*  as published by the Free Software Foundation; either version 2 of
*  the License, or (at your option) any later version.
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public
*  License along with this program; if not, write to the Free Software
*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

import java.awt.Rectangle;

public class Main {
    /**
     * Convert a {@link Rectangle} object to a comma separated string in the
     * format of <code>x,y,width,height</code>. Suitable for storing
     * rectangles in property files, XML files etc.
     * 
     * @param rectangle rectangle
     * @return comman separated string x,y,width,height
     */
    public static String rectangleToString(Rectangle rectangle) {
        StringBuffer buf = new StringBuffer(String.valueOf(rectangle.x));
        buf.append(',');
        buf.append(String.valueOf(rectangle.y));
        buf.append(',');
        buf.append(String.valueOf(rectangle.width));
        buf.append(',');
        buf.append(String.valueOf(rectangle.height));
        return buf.toString();
    }
}

Related

  1. getRectangle(Properties prop, final String key, final Rectangle def)
  2. getRectangle(String rectStr)
  3. newRectangle(int x1, int y1, int x2, int y2)
  4. rectangleToString(Rectangle r)
  5. rectangleToString(Rectangle r)
  6. storeBounds(String name, Window window)
  7. stringToBounds(String str, Rectangle defaultRect)
  8. stringToRectangle(String s)
  9. stringToRectangle(String s, Rectangle defaultValue)