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(int x, int y, int width, int height) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.

Usage

From source file:Main.java

public static void main(String[] args) {

    AffineTransform tx = new AffineTransform();
    tx.translate(1, 10);/*from  ww w .j a v a 2s.c  o  m*/
    Rectangle shape = new Rectangle(1, 1, 1, 1);
    Shape newShape = tx.createTransformedShape(shape);

    System.out.println("done");

}

From source file:BasicShapes.java

public static void main(String[] args) {

    AffineTransform tx = new AffineTransform();
    tx.translate(1, 10);/*from   w  ww. j  a va  2 s  .com*/
    Rectangle shape = new Rectangle(1, 1, 1, 1);
    Shape newShape = tx.createTransformedShape(shape);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();
    int x = 100;/*from www.  j a  v  a 2 s .  c  om*/
    int y = 100;
    int width = 200;
    int height = 200;
    Rectangle area = new Rectangle(x, y, width, height);
    BufferedImage bufferedImage = robot.createScreenCapture(area);

    area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    bufferedImage = robot.createScreenCapture(area);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();
    int x = 100;/*from   w ww  .  j av  a 2 s .  c  o  m*/
    int y = 100;
    int width = 200;
    int height = 200;
    Rectangle area = new Rectangle(x, y, width, height);
    BufferedImage bufferedImage = robot.createScreenCapture(area);

    // Capture the whole screen
    area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    bufferedImage = robot.createScreenCapture(area);

}

From source file:Main.java

public static void main(String[] arg) throws Exception {
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    Robot robot = new Robot();

    BufferedImage image = robot/* w w  w .jav a2s  .  com*/
            .createScreenCapture(new Rectangle(0, 0, (int) screenDim.getWidth(), (int) screenDim.getHeight()));

    JWindow window = new JWindow(new JFrame());
    window.getContentPane().setLayout(new BorderLayout());
    window.getContentPane().add(BorderLayout.CENTER, new JLabel(new ImageIcon(image)));
    window.pack();
    window.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    Image chunk = readFragment(url.openStream(), new Rectangle(15, 15, 30, 25));
    JOptionPane.showMessageDialog(null, new ImageIcon(chunk), "Duke", JOptionPane.INFORMATION_MESSAGE);

}

From source file:MainClass.java

public static void main(String[] args) {
    ImageObserver myObserver = new ImageObserver() {
        public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) {
            if ((flags & HEIGHT) != 0)
                System.out.println("Image height = " + height);
            if ((flags & WIDTH) != 0)
                System.out.println("Image width = " + width);
            if ((flags & FRAMEBITS) != 0)
                System.out.println("Another frame finished.");
            if ((flags & SOMEBITS) != 0)
                System.out.println("Image section :" + new Rectangle(x, y, width, height));
            if ((flags & ALLBITS) != 0)
                System.out.println("Image finished!");
            if ((flags & ABORT) != 0)
                System.out.println("Image load aborted...");
            return true;
        }//from w  w w .ja  va 2 s  .  c  o  m
    };

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image img = toolkit.getImage(args[0]);
    toolkit.prepareImage(img, -1, -1, myObserver);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame f = new JFrame(Main.class.getSimpleName());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    BufferedImage bi = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel(new ImageIcon(bi));
    panel.add(label);//from   w ww . ja  va 2s  .c  om
    MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {
        @Override
        public void mouseDragged(MouseEvent e) {
            Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
            ((JPanel) e.getSource()).scrollRectToVisible(r);
        }
    };
    panel.addMouseMotionListener(doScrollRectToVisible);

    panel.setAutoscrolls(true);
    f.add(new JScrollPane(panel));
    f.pack();
    f.setSize(f.getWidth() / 2, f.getHeight() / 2);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage bi = ImageIO.read(url);
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from  w ww .  j  a v  a2  s  .co m*/
        public void run() {
            int strokeWidth = 12;
            int pad = 50;
            Shape shape = new Rectangle(pad, pad, bi.getWidth() - (2 * pad), bi.getHeight() - (2 * pad));
            Image i = getStrokedImage(bi, shape, strokeWidth);
            JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(i)));
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    int ROWS = 100;
    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(new JLabel("Thanks for helping out. Use tab to move around."));
    for (int i = 0; i < ROWS; i++) {
        JTextField field = new JTextField("" + i);
        field.setName("field#" + i);
        content.add(field);/*from  w w  w.  jav  a 2s  .c o  m*/
    }
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner",
            new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (!(evt.getNewValue() instanceof JComponent)) {
                        return;
                    }
                    JViewport viewport = (JViewport) content.getParent();
                    JComponent focused = (JComponent) evt.getNewValue();
                    if (content.isAncestorOf(focused)) {
                        Rectangle rect = focused.getBounds();
                        Rectangle r2 = viewport.getVisibleRect();
                        content.scrollRectToVisible(
                                new Rectangle(rect.x, rect.y, (int) r2.getWidth(), (int) r2.getHeight()));
                    }
                }
            });
    JFrame window = new JFrame();
    window.setContentPane(new JScrollPane(content));
    window.setSize(200, 200);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
}