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:org.chos.transaction.passport.controller.CaptchaController.java

@RequestMapping(value = "/captcha")
public void captcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
    BufferedImage bi = new BufferedImage(40, 18, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    String c = generate();//from w w w.ja v a  2 s.co  m
    g.setColor(Color.white);
    g.fillRect(1, 1, 38, 16);

    g.setColor(generateColor());
    g.drawString(c, 4, 13);
    response.setContentType("image/jpeg");
    ServletOutputStream os = response.getOutputStream();
    //      os.write(b)
    //      ImageIO.createImageOutputStream(os);
    ImageIO.write(bi, "jpg", os);
    os.flush();
    os.close();
    request.getSession().setAttribute("captcha", c);
}

From source file:com.foudroyantfactotum.mod.fousarchive.midi.generation.MidiImageGeneration.java

public ImmutablePair<String, BufferedImage> buildImage() throws InterruptedException, ExecutionException {
    final Future<String> name = pool.submit(new LineProcessor(imgX));
    final BufferedImage mdbf = new BufferedImage(imgX, imgY, BufferedImage.TYPE_BYTE_GRAY);
    final Graphics g = mdbf.getGraphics();

    g.setColor(Color.BLACK);//from  ww w.ja va  2 s . c o m
    g.fillRect(0, 0, imgX, imgY);
    g.setColor(Color.WHITE);

    for (Line l = lines.take(); l != TERMINATE; l = lines.take()) {
        g.drawLine(l.note, (int) Math.round(l.tickStart * imgY), l.note, (int) Math.round(l.tickEnd * imgY));
    }

    pool.shutdown();

    g.dispose();

    return ImmutablePair.of(name.get(), mdbf);
}

From source file:com.lixiaocong.service.ImageCodeService.java

public BufferedImage getImage(HttpSession session) {
    //background//from   ww w .ja va  2s  . co  m
    BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics graphics = bi.getGraphics();
    graphics.setColor(randomColor());
    graphics.fillRect(0, 0, WIDTH, HEIGHT);

    //content
    StringBuilder sb = new StringBuilder();
    int len = ch.length;
    Random random = new Random();
    for (int i = 0; i < 4; i++) {
        int index = random.nextInt(len);
        graphics.setColor(randomColor());
        graphics.setFont(new Font(null, Font.BOLD + Font.ITALIC, 30));
        graphics.drawString(ch[index] + "", i * 15 + 5, 25);
        sb.append(ch[index]);
    }
    session.setAttribute("imagecode", sb.toString());

    //lines
    for (int i = 0; i < 4; i++) {
        graphics.setColor(randomColor());
        graphics.drawLine(random.nextInt(WIDTH), random.nextInt(HEIGHT), random.nextInt(WIDTH),
                random.nextInt(HEIGHT));
    }

    return bi;
}

From source file:Main.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(color);//from   ww  w  .  ja  va2s.  c om
    switch (value) {
    case 1:
        g.fillRect(3 * SIDE, 3 * SIDE, SIDE, SIDE);
        break;
    case 2:
        g.fillRect(5 * SIDE, SIDE, SIDE, SIDE);
        g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE);
        break;
    case 3:
        g.fillRect(5 * SIDE, SIDE, SIDE, SIDE);
        g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE);
        g.fillRect(3 * SIDE, 3 * SIDE, SIDE, SIDE);
        break;
    case 4:
        g.fillRect(SIDE, SIDE, SIDE, SIDE);
        g.fillRect(5 * SIDE, 5 * SIDE, SIDE, SIDE);
        g.fillRect(5 * SIDE, SIDE, SIDE, SIDE);
        g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE);
        break;
    case 5:
        g.fillRect(SIDE, SIDE, SIDE, SIDE);
        g.fillRect(5 * SIDE, 5 * SIDE, SIDE, SIDE);
        g.fillRect(5 * SIDE, SIDE, SIDE, SIDE);
        g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE);
        g.fillRect(3 * SIDE, 3 * SIDE, SIDE, SIDE);
        break;
    case 6:
        g.fillRect(SIDE, SIDE, SIDE, SIDE);
        g.fillRect(5 * SIDE, 5 * SIDE, SIDE, SIDE);
        g.fillRect(5 * SIDE, SIDE, SIDE, SIDE);
        g.fillRect(SIDE, 5 * SIDE, SIDE, SIDE);
        g.fillRect(SIDE, 3 * SIDE, SIDE, SIDE);
        g.fillRect(5 * SIDE, 3 * SIDE, SIDE, SIDE);
        break;
    }
}

From source file:ImageBorderHack.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    g.setColor(Color.white);/*from   w w w.  jav a2 s.com*/
    g.fillRect(x, y, width, height);

    Graphics2D g2 = (Graphics2D) g;

    int tlw = topLeftImage.getWidth(null);
    int tlh = topLeftImage.getHeight(null);
    int tcw = topCenterImage.getWidth(null);
    int tch = topCenterImage.getHeight(null);
    int trw = topRight.getWidth(null);
    int trh = topRight.getHeight(null);

    int lcw = leftCenterImage.getWidth(null);
    int lch = leftCenterImage.getHeight(null);
    int rcw = rightCenterImage.getWidth(null);
    int rch = rightCenterImage.getHeight(null);

    int blw = bottomLeftImage.getWidth(null);
    int blh = bottomLeftImage.getHeight(null);
    int bcw = bottomCenterImage.getWidth(null);
    int bch = bottomCenterImage.getHeight(null);
    int brw = bottomRightImage.getWidth(null);
    int brh = bottomRightImage.getHeight(null);

    fillTexture(g2, topLeftImage, x, y, tlw, tlh);
    fillTexture(g2, topCenterImage, x + tlw, y, width - tlw - trw, tch);
    fillTexture(g2, topRight, x + width - trw, y, trw, trh);

    fillTexture(g2, leftCenterImage, x, y + tlh, lcw, height - tlh - blh);
    fillTexture(g2, rightCenterImage, x + width - rcw, y + trh, rcw, height - trh - brh);

    fillTexture(g2, bottomLeftImage, x, y + height - blh, blw, blh);
    fillTexture(g2, bottomCenterImage, x + blw, y + height - bch, width - blw - brw, bch);
    fillTexture(g2, bottomRightImage, x + width - brw, y + height - brh, brw, brh);
}

From source file:painting.SwingPaintDemo3.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawString("This is my custom Panel!", 10, 20);
    g.setColor(Color.RED);//from www.  java  2  s  . c  o m
    g.fillRect(squareX, squareY, squareW, squareH);
    g.setColor(Color.BLACK);
    g.drawRect(squareX, squareY, squareW, squareH);
}

From source file:Main.java

public void paint(Graphics g) {
    int w = getSize().width;
    int h = getSize().height;

    Ellipse2D e = new Ellipse2D.Float(w / 4.0f, h / 4.0f, w / 2.0f, h / 2.0f);
    g.setClip(e);/*  w w w.j a v a2s.  co  m*/

    g.setColor(Color.red);
    g.fillRect(0, 0, w, h);

}

From source file:ImageTransferTest.java

public ImageTransferFrame() {
    setTitle("ImageTransferTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    label = new JLabel();
    image = new BufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();
    g.setColor(Color.WHITE);//from w  ww  .j  a  v a  2s  .  co  m
    g.fillRect(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    g.setColor(Color.RED);
    g.fillOval(DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2);

    label.setIcon(new ImageIcon(image));
    add(new JScrollPane(label), BorderLayout.CENTER);
    JPanel panel = new JPanel();

    JButton copyButton = new JButton("Copy");
    panel.add(copyButton);
    copyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            copy();
        }
    });

    JButton pasteButton = new JButton("Paste");
    panel.add(pasteButton);
    pasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            paste();
        }
    });

    add(panel, BorderLayout.SOUTH);
}

From source file:DebugFrame.java

/**
 * Clears the back buffer/*  w w w.j a  v  a  2  s.  c om*/
 */
public void clear() {
    Graphics g = panel.buff.getGraphics();

    g.setColor(Color.white);
    g.fillRect(0, 0, panel.getWidth(), panel.getHeight());
}

From source file:test.uk.co.modularaudio.util.audio.controlinterpolation.InterpolatorVisualiser.java

@Override
public void paint(final Graphics g) {
    g.setColor(Color.WHITE);//from  w  ww  .  jav a2  s .co m
    g.fillRect(0, 0, SwingControlInterpolatorAnalyser.VIS_WIDTH + 1,
            SwingControlInterpolatorAnalyser.VIS_HEIGHT + 1);
    if (controlSrcVisualiser != null) {
        controlSrcVisualiser.paint(g);
    }
    g.drawImage(bi, 0, 0, null);
}