Example usage for java.awt Graphics fillRect

List of usage examples for java.awt Graphics fillRect

Introduction

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

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

From source file:FillRectPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawRect(10, 10, 80, 30);//  ww  w. j  av a2  s  .co  m
    g.drawRoundRect(100, 10, 80, 30, 15, 15);
    g.drawOval(10, 100, 80, 30);
    g.setColor(Color.red);
    g.fillRect(10, 10, 80, 30);
    g.fillRoundRect(100, 10, 80, 30, 15, 15);

    int thickness = 4;

    g.fill3DRect(200, 10, 80, 30, true);
    for (int i = 1; i <= thickness; i++)
        g.draw3DRect(200 - i, 10 - i, 80 + 2 * i - 1, 30 + 2 * i - 1, true);

    g.fill3DRect(200, 50, 80, 30, false);
    for (int i = 1; i <= thickness; i++)
        g.draw3DRect(200 - i, 50 - i, 80 + 2 * i - 1, 30 + 2 * i - 1, true);

    g.fillOval(10, 100, 80, 30);
}

From source file:ColorSource.java

public void dragGestureRecognized(DragGestureEvent e) {
    // Create an image we can drag along with us.
    // Not all systems support this, but it doesn't hurt to try.
    Image colorblock = this.createImage(25, 25);
    Graphics g = colorblock.getGraphics();
    g.setColor(color);//w ww. ja  v  a2s  . c  om
    g.fillRect(0, 0, 25, 25);

    // Start dragging our transferable color object.
    e.startDrag(DragSource.DefaultMoveDrop, // The initial drag cursor
            colorblock, new Point(0, 0), // The image to drag
            tcolor, // The data being dragged
            this); // Who to notify during drag
}

From source file:MyCanvas.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // draw entire component white
    g.setColor(Color.white);/*from  w  w  w. j a v a2  s  .c om*/
    g.fillRect(0, 0, getWidth(), getHeight());

    // yellow circle
    g.setColor(Color.yellow);
    g.fillOval(0, 0, 240, 240);

    // magenta circle
    g.setColor(Color.magenta);
    g.fillOval(160, 160, 240, 240);

    // paint the icon below blue sqaure
    int w = java2sLogo.getIconWidth();
    int h = java2sLogo.getIconHeight();
    java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2));

    // paint the icon below red sqaure
    java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2));

    // transparent red square
    g.setColor(m_tRed);
    g.fillRect(60, 220, 120, 120);

    // transparent green circle
    g.setColor(m_tGreen);
    g.fillOval(140, 140, 120, 120);

    // transparent blue square
    g.setColor(m_tBlue);
    g.fillRect(220, 60, 120, 120);

    g.setColor(Color.black);

    g.setFont(monoFont);
    FontMetrics fm = g.getFontMetrics();
    w = fm.stringWidth("Java Source");
    h = fm.getAscent();
    g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4));

    g.setFont(sanSerifFont);
    fm = g.getFontMetrics();
    w = fm.stringWidth("and");
    h = fm.getAscent();
    g.drawString("and", 200 - (w / 2), 200 + (h / 4));

    g.setFont(serifFont);
    fm = g.getFontMetrics();
    w = fm.stringWidth("Support.");
    h = fm.getAscent();
    g.drawString("Support.", 280 - (w / 2), 280 + (h / 4));
}

From source file:test.buddhabrot.BuddhabrotApp.java

public BuddhabrotApp(final GridNode node) throws HeadlessException {
    super();/*from ww w. ja  v a2 s .c  o m*/
    setSize(WIDTH, HEIGHT);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {

            try {
                if (future != null) {

                    if (!future.isJobFinished()) {
                        log.info("Cancelling Job... wait");
                        setTitle("Cancelling Job - WAIT");
                        if (!future.cancel()) {
                            log.warn("Cancel Failed");
                        }
                    }
                }

                node.shutdown();
                // Give time to send termination message
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            System.exit(0);
        }

    });

    setVisible(true);

    // create off-screen buffer
    Graphics g = image.getGraphics();
    g.setColor(Color.black);
    g.fillRect(0, 0, WIDTH, HEIGHT);
    repaint();
}

From source file:net.d53dev.dslfy.web.service.GifService.java

public BufferedImage convertRGBAToGIF(BufferedImage src, int transColor) {
    BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = dst.getGraphics();
    g.setColor(new Color(transColor));
    g.fillRect(0, 0, dst.getWidth(), dst.getHeight());
    {//from w  ww. ja v  a 2s  .co m
        IndexColorModel indexedModel = (IndexColorModel) dst.getColorModel();
        WritableRaster raster = dst.getRaster();
        int sample = raster.getSample(0, 0, 0);
        int size = indexedModel.getMapSize();
        byte[] rr = new byte[size];
        byte[] gg = new byte[size];
        byte[] bb = new byte[size];
        indexedModel.getReds(rr);
        indexedModel.getGreens(gg);
        indexedModel.getBlues(bb);
        IndexColorModel newModel = new IndexColorModel(8, size, rr, gg, bb, sample);
        dst = new BufferedImage(newModel, raster, dst.isAlphaPremultiplied(), null);
    }
    dst.createGraphics().drawImage(src, 0, 0, null);
    return dst;
}

From source file:QandE.SquareIcon.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    if (c.isEnabled()) {
        g.setColor(Color.RED);/* w ww  .  j a  v  a  2  s. co m*/
    } else {
        g.setColor(Color.GRAY);
    }

    g.fillRect(x, y, SIZE, SIZE);
}

From source file:org.pmedv.core.app.PostApplicationStartupConfigurer.java

public PostApplicationStartupConfigurer(String fileLocation) {
    this.fileLocation = fileLocation;
    log.info(AppContext.getName() + " initialized.");
    BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();
    g.setColor(Color.BLACK);// ww  w.  ja v  a 2s .  c  o m
    g.fillRect(0, 0, 16, 16);
    AppContext.getContext().getBean(ApplicationWindow.class).getStatusLabel().setIcon(new ImageIcon(image));
}

From source file:no.java.swing.SelectableLabel.java

@Override
protected void paintComponent(Graphics g) {
    if (isOpaque()) {
        g.setColor(getBackground());/*from   w  w  w.ja  v a2  s . c  om*/
        g.fillRect(0, 0, getWidth(), getHeight());
    }
}

From source file:com.synnex.saas.platform.core.servlet.CaptchaServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*  w w w . j av  a  2 s.c o m*/
        int width = 50;
        int height = 18;
        String captchaCode = RandomStringUtils.random(4, true, true);
        HttpSession session = request.getSession(true);
        session.setAttribute("captchaCode", captchaCode);

        response.setContentType("images/jpeg");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);

        ServletOutputStream out = response.getOutputStream();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setColor(getRandColor(200, 250));
        g.fillRect(0, 0, width, height);
        Font mFont = new Font("Times New Roman", Font.BOLD, 18);
        g.setFont(mFont);
        g.setColor(getRandColor(160, 200));
        Random random = new Random();
        for (int i = 0; i < 155; i++) {
            int x2 = random.nextInt(width);
            int y2 = random.nextInt(height);
            int x3 = random.nextInt(12);
            int y3 = random.nextInt(12);
            g.drawLine(x2, y2, x2 + x3, y2 + y3);
        }
        g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        g.drawString(captchaCode, 2, 16);
        g.dispose();
        ImageIO.write((BufferedImage) image, "JPEG", out);
        out.close();
    } catch (Exception e) {
        logger.error("Generate captcha failed.", e);
    }
}

From source file:Layers.java

public void paint(Graphics g) {
    Color c1 = new Color(200, 100, 100, 50); // r, g, b, a
    Color c2 = new Color(100, 200, 000, 128);
    Color c3 = new Color(100, 200, 000, 255);
    g.setColor(c1);// w w w.  j  a  v  a2 s . c om
    g.fillRect(0, 0, width / 2, height / 2);
    g.setColor(c2);
    g.fillRect(width / 4, height / 4, width / 2, height / 2);
    g.setColor(c3);
    g.fillRect(width / 3, height / 3, width / 4, height / 4);
}