Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

In this page you can find the example usage for java.awt Rectangle Rectangle.

Prototype

public Rectangle(Point p, Dimension d) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified by the Point argument, and whose width and height are specified by the Dimension argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    Rectangle r = new Rectangle(100, 325);
    Class c = r.getClass();/*from www.java  2 s  .c  o  m*/
    try {
        Field heightField = c.getField("height");
        heightField.setInt(r, 1000);
        Integer heightValue = (Integer) heightField.get(r);
        System.out.println("Height: " + heightValue.toString());
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) {
    Rectangle r = new Rectangle(100, 325);
    Class c = r.getClass();/*from   ww  w . j av a  2 s. c o  m*/
    try {
        Field heightField = c.getField("height");
        Integer heightValue = (Integer) heightField.get(r);
        System.out.println("Height: " + heightValue.toString());
    } catch (NoSuchFieldException e) {
        System.out.println(e);
    } catch (SecurityException e) {
        System.out.println(e);
    } catch (IllegalAccessException e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame() {
        @Override/*from   w w w .j a va  2  s  . c  o m*/
        public synchronized void setExtendedState(int state) {
            if (isUndecorated() && (state & MAXIMIZED_BOTH) == MAXIMIZED_BOTH) {
                super.setMaximizedBounds(new Rectangle(300, 300));
            }
            super.setExtendedState(state);
        }
    };
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800, 600);
    frame.setUndecorated(true);
    frame.getContentPane().add(new JButton(new AbstractAction("Toggle maximize") {
        @Override
        public void actionPerformed(ActionEvent e) {
            int state = frame.getExtendedState();
            if ((state & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) {
                frame.setExtendedState(JFrame.NORMAL);
            } else {
                frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
            }
        }
    }), BorderLayout.PAGE_END);
    frame.setVisible(true);
}

From source file:SampleSet.java

public static void main(String[] args) {
    Rectangle r = new Rectangle(100, 20);
    System.out.println("original: " + r.toString());
    modifyWidth(r, new Integer(300));
    System.out.println("modified: " + r.toString());
}

From source file:SampleGet.java

public static void main(String[] args) {
    Rectangle r = new Rectangle(100, 325);
    printHeight(r);

}

From source file:com.orsonpdf.demo.PDFBarChartDemo1.java

/**
 * Starting point for the demo./*from w  w  w.  jav a 2s.c o m*/
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    PDFDocument pdfDoc = new PDFDocument();
    pdfDoc.setTitle("PDFBarChartDemo1");
    pdfDoc.setAuthor("Object Refinery Limited");
    Page page = pdfDoc.createPage(new Rectangle(612, 468));
    PDFGraphics2D g2 = page.getGraphics2D();
    chart.draw(g2, new Rectangle(0, 0, 612, 468));
    pdfDoc.writeToFile(new File("PDFBarChartDemo1.pdf"));
}

From source file:com.orsonpdf.demo.PDFPieChartDemo1.java

/**
 * Starting point for the demo./*from  www  .  ja  va  2  s .  c o  m*/
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    PDFDocument pdfDoc = new PDFDocument();
    pdfDoc.setTitle("PDFPieChartDemo1");
    pdfDoc.setAuthor("Object Refinery Limited");
    Page page = pdfDoc.createPage(new Rectangle(612, 468));
    PDFGraphics2D g2 = page.getGraphics2D();
    g2.setRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION, true);
    chart.draw(g2, new Rectangle(0, 0, 612, 468));
    File f = new File("PDFPieChartDemo1.pdf");
    pdfDoc.writeToFile(f);
}

From source file:Main.java

/**
 * Creates a buffered image for the given parameters. If there is not enough
 * memory to create the image then a OutOfMemoryError is thrown.
 *//*from  ww w .j  a  v a2  s .  co m*/
public static BufferedImage createBufferedImage(int w, int h, Color background) {
    BufferedImage result = null;

    if (w > 0 && h > 0) {
        int type = (background != null) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
        result = new BufferedImage(w, h, type);

        // Clears background
        if (background != null) {
            Graphics2D g2 = result.createGraphics();
            clearRect(g2, new Rectangle(w, h), background);
            g2.dispose();
        }
    }

    return result;
}

From source file:Main.java

/**
 * Returns component bounds on screen.//  w  w w  .j  a  v a2  s.  c o  m
 *
 * @param component
 *            component to process
 * @return component bounds on screen
 */
public static Rectangle getBoundsOnScreen(final Component component) {
    return new Rectangle(component.getLocationOnScreen(), component.getSize());
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(10, 10);

    g2.fill(r);/*from   www  .  ja v  a  2 s. co m*/
    System.out.println(r.isEmpty());
}