Java Code Examples for java.awt.Graphics.fillRect()

The following are Jave code examples for showing how to use fillRect() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: smile_1.5.0_java7   File: ColorCellEditor.java   View Source Code Vote up 6 votes
/**
 * Constructor.
 */
public ColorCellEditor() {
    button = new JButton() {
        @Override
        public void paintComponent(Graphics g) {
            // When the buttons are pressed they are redrawn with the default
            // background color but not what we want.
            g.setColor(getBackground());
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    
    button.setActionCommand(EDIT);
    button.addActionListener(this);

    //Set up the dialog that the button brings up.
    colorChooser = new JColorChooser();
    dialog = JColorChooser.createDialog(button, "Pick a Color", true, colorChooser, this, null);
}
 
Example 2
Project: jdk8u-jdk   File: EncodeSubImageTest.java   View Source Code Vote up 6 votes
private static BufferedImage createTestImage() {
    int w = 100;
    int h = 100;

    BufferedImage src = new BufferedImage(w, h,
            BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = src.createGraphics();
    g.setColor(Color.red);
    g.fillRect(0, 0, w, h);
    g.setColor(Color.green);
    g.fillRect(subImageOffset, subImageOffset,
            w - 2 * subImageOffset, h - 2* subImageOffset);
    g.setColor(Color.blue);
    g.fillRect(2 * subImageOffset, 2 * subImageOffset,
            w - 4 * subImageOffset, h - 4 * subImageOffset);
    g.dispose();

    return src;
}
 
Example 3
Project: BassNES   File: Visualizer.java   View Source Code Vote up 6 votes
private void colorBlack(Graphics g,String note){
	char pitch = note.charAt(1);
	char octave = note.charAt(3);
	int xoffset = (Integer.parseInt(octave+""))*113;
	int xoffset2 = 0;
	switch(pitch){
	case 'C':
		xoffset+=14;
		xoffset2 = 23-14;break;
	case 'D':
		xoffset+=28;
		xoffset2=37-28;break;
	case 'F':
		xoffset+=61;
		xoffset2= 71-61;break;
	case 'G':
		xoffset+= 76;
		xoffset2 = 86-76;break;
	case 'A':
		xoffset+=92;
		xoffset2=102-92;break;
	}
	g.fillRect(xoffset, 0, xoffset2, 41);
}
 
Example 4
Project: jdk8u-jdk   File: ImageGenerator.java   View Source Code Vote up 6 votes
public ImageGenerator(int _width, int _height, Color bgColor)
{
      width = _width;
      height = _height;
      bi = new BufferedImage(
          width,
          height,
          BufferedImage.TYPE_INT_ARGB);
      Graphics gr = bi.getGraphics();
      if(null==bgColor){
          bgColor = Color.WHITE;
      }
      gr.setColor(bgColor);
      gr.fillRect(0, 0, width, height);
      paint(gr);
      gr.dispose();
}
 
Example 5
Project: NeuralNet   File: JTela.java   View Source Code Vote up 6 votes
public int[][] disegna(Graphics g, int corX, int corY) {
    int puntoX, puntoY;
    
    //Controlla in quale blocco si sta disegnando
    puntoX = corX / (larg/bloccoX);
    puntoY = corY / (alt/bloccoY);
    
    try {
        pixel[puntoY][puntoX] = 1;
    } catch (Exception e) {}
    
    g.fillRect(corX-sizeColore/2, corY-sizeColore/2, sizeColore, sizeColore);
    
    //Pulisce lo schermo
    for (int i = 0; i<20; ++i) System.out.println();
    //Stampa la matrice di pixel
    for (int k=0; k<pixel.length; k++) {
        for (int tmp : pixel[k])
            System.out.print(tmp + " ");
        System.out.println();
    }
    return pixel;
}
 
Example 6
Project: jdk8u-jdk   File: AcceleratedScaleTest.java   View Source Code Vote up 6 votes
private static void initVI(GraphicsConfiguration gc) {
    int res;
    if (destVI == null) {
        res = VolatileImage.IMAGE_INCOMPATIBLE;
    } else {
        res = destVI.validate(gc);
    }
    if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
        if (destVI != null) destVI.flush();
        destVI = gc.createCompatibleVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
        destVI.validate(gc);
        res = VolatileImage.IMAGE_RESTORED;
    }
    if (res == VolatileImage.IMAGE_RESTORED) {
        Graphics vig = destVI.getGraphics();
        vig.setColor(Color.red);
        vig.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
        vig.dispose();
    }
}
 
Example 7
Project: java-course   File: BarChartComponent.java   View Source Code Vote up 6 votes
/**
 * Draws graph bars on component
 * 
 * @param g
 *            The {@link Graphics} object.
 */
private void drawBars(Graphics g) {

    for (int i = 0; i < vLines; i++) {
        int yValue = chart.getValues().get(i).getY();

        // Orange color
        g.setColor(new Color(245, 121, 49));
        g.fillRect(xPoint + 1 + i * vStep, (rect.height - yPoint - yValue
                * hStep / chart.getyStep()), vStep - 1, yValue * hStep
                / chart.getyStep() - 1);

        // Shadow
        g.setColor(new Color(0.6509f, 0.6588f, 0.6275f, 0.6f));
        g.fillRect(xPoint + 2 + (i + 1) * vStep, (rect.height - yPoint
                - yValue * hStep / chart.getyStep() + 5), 5, yValue * hStep
                / chart.getyStep() - 10);
    }
}
 
Example 8
Project: incubator-netbeans   File: ImagePanel.java   View Source Code Vote up 6 votes
protected void paintComponent(Graphics graphics) {
    graphics.setColor(getBackground());
    graphics.fillRect(0, 0, getWidth(), getHeight());

    switch (imageAlign) {
        case (SwingConstants.TOP):
            graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);

            break;
        case (SwingConstants.BOTTOM):
            graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, getHeight() - image.getHeight(null), this);

            break;
        default:
            graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);
    }
}
 
Example 9
Project: LivroJavaComoProgramar10Edicao   File: MyRect.java   View Source Code Vote up 5 votes
public void draw(Graphics g)
{
   g.setColor(getColor());
   
   if (isFilled())
      g.fillRect(getUpperLeftX(), getUpperLeftY(),
         getWidth(), getHeight());
   else
      g.drawRect(getUpperLeftX(), getUpperLeftY(),
         getWidth(), getHeight());
}
 
Example 10
Project: jmt   File: FastGraph.java   View Source Code Vote up 5 votes
/**
 * Draws the selected value
 * @param selectedValue the selected value to draw
 * @param g the graphics object
 * @param width the total chart width
 * @param height the total chart height
 * @param maxx the maximum X value (simulation time)
 * @param maxy the maximum Y value
 */
private void paintSelectedValue(MeasureValue selectedValue, Graphics g, int width, int height, double maxx, double maxy) {
	FontMetrics metric = g.getFontMetrics();
	String x_str = simulationTimeFormat.format(selectedValue.getSimTime());
	String m_str = formatNumber(selectedValue.getMeanValue());
	String i_str = formatNumber(selectedValue.getLastIntervalAvgValue());
	
	Dimension bounds = composeVerticalBounds(g, metric, POPUP_FULL_X_PREFIX + x_str, POPUP_FULL_X_PREFIX + m_str, POPUP_FULL_X_PREFIX + i_str);
	int selectedValueX = getX(selectedValue.getSimTime());
	int textX = (int)(selectedValueX - bounds.getWidth() / 2);
	// Fix value out of chart for label
	if (textX < 2) {
		textX = 2;
	} else if (textX + bounds.getWidth() + POPUP_MARGIN > width) {
		textX = width - (int)bounds.getWidth() - POPUP_MARGIN;
	}
	int textY = getY(maxy / 2) + (int)bounds.getHeight() / 2;
	
	g.setColor(COLOR_POPUP);
	g.drawLine(selectedValueX, getY(0), selectedValueX, getY(selectedValue.getLastIntervalAvgValue()));
	g.setColor(COLOR_POPUP_BG);
	g.fillRoundRect(textX - POPUP_MARGIN, textY - (int)bounds.getHeight(), (int)bounds.getWidth() + POPUP_MARGIN * 2, (int)bounds.getHeight() + POPUP_MARGIN, 4, 4);	
	g.setColor(COLOR_POPUP);
	g.drawRoundRect(textX - POPUP_MARGIN, textY - (int)bounds.getHeight(), (int)bounds.getWidth() + POPUP_MARGIN * 2, (int)bounds.getHeight() + POPUP_MARGIN, 4, 4);
	
	// Draw squares
	Rectangle2D prefixBounds = metric.getStringBounds(POPUP_X_PREFIX, g);
	g.setColor(COLOR_DRAW);
	g.fillRect(textX, textY - (int)prefixBounds.getHeight() - bounds.height / 3, (int)prefixBounds.getWidth(), (int)prefixBounds.getHeight());
	g.setColor(COLOR_LAST_INTERVAL);
	g.fillRect(textX, textY - (int)prefixBounds.getHeight(), (int)prefixBounds.getWidth(), (int)prefixBounds.getHeight());
	
	// Draws texts
	g.setColor(COLOR_AXIS);
	g.drawString(POPUP_FULL_X_PREFIX + x_str, textX, textY - bounds.height * 2 / 3);
	g.drawString(POPUP_MIDDLE + m_str, textX + (int)prefixBounds.getWidth(), textY - bounds.height / 3);
	g.drawString(POPUP_MIDDLE + i_str, textX + (int)prefixBounds.getWidth(), textY);
}
 
Example 11
Project: imagetozxspec   File: PreviewLabeller.java   View Source Code Vote up 5 votes
/**
 * Draws the given label onto the output image in the top left corner in white.
 * 
 * @param output the image to write the label on
 * @param label the label, usually the preview strategy name, to write onto the image
 */
static void drawPreviewStrategyWithName(BufferedImage output, String label) {
	Graphics g = output.getGraphics();
	g.setFont(g.getFont().deriveFont(Font.BOLD));
	int height = g.getFontMetrics().getHeight();
	int width = g.getFontMetrics().stringWidth(label);
	g.setColor(Color.WHITE);
	g.fillRect(0, 20-g.getFontMetrics().getAscent(), width, height);
	g.setColor(Color.BLACK);
	g.drawString(label,0,20);
	g.dispose();
}
 
Example 12
Project: etomica   File: DisplayPolytopeCanvas2D.java   View Source Code Vote up 5 votes
/**
 * doPaint is the method that handles the drawing of the box to the screen.
 * Several variables and conditions affect how the image is drawn.  First,
 * the Unit.Length.Sim class variable <code>TO_PIXELS</code> performs the conversion 
 * between polytope dimensions and pixels.  The default value is 10 pixels/unit length
 * reflecting the default size of the box (300 pixels by 300 pixels) and the
 * default polytope size (30 by 30).
 *
 * @param g The graphic object to which the image of the box is drawn
 */
public void doPaint(Graphics g) {
    if(!isVisible() || displayPolytope.getPolytope() == null) {return;}
    int w = getSize().width;
    int h = getSize().height;
    
    g.setColor(getBackground());
    g.fillRect(0,0,w,h);
    displayPolytope.computeImageParameters2(w, h);

    //Draw other features if indicated
    if(drawBoundary>DRAW_BOUNDARY_NONE) {
        g.setColor(Color.gray);
        double toPixels = displayPolytope.getScale()*pixel.toPixels();
        Polygon shape = (Polygon)displayPolytope.getPolytope();
        LineSegment[] edges = shape.getEdges();
        int ox = displayPolytope.getOrigin()[0];
        int oy = displayPolytope.getOrigin()[1];
        for(int i=0; i<edges.length; i++) {
            int x1 = ox + (int)(toPixels*edges[i].getVertices()[0].getX(0));
            int y1 = oy + (int)(toPixels*edges[i].getVertices()[0].getX(1));
            int x2 = ox + (int)(toPixels*edges[i].getVertices()[1].getX(0));
            int y2 = oy + (int)(toPixels*edges[i].getVertices()[1].getX(1));
            g.drawLine(x1,y1,x2,y2);
        }
    }

}
 
Example 13
Project: ScreenCut   File: ScreenCut.java   View Source Code Vote up 5 votes
/**
 * 绘制方形
 */
private void drawRect(Point st, Point ed, Color c, Graphics g, int thick) {
    g.setColor(c);
    g.fillRect(Math.min(st.x, ed.x), st.y, Math.abs(ed.x - st.x), thick);//横线1
    g.fillRect(Math.min(st.x, ed.x), ed.y, Math.abs(ed.x - st.x) + thick, thick);//横线2
    g.fillRect(st.x, Math.min(st.y, ed.y), thick, Math.abs(ed.y - st.y));//竖线1
    g.fillRect(ed.x, Math.min(st.y, ed.y), thick, Math.abs(ed.y - st.y));//坚线2
}
 
Example 14
Project: openjdk-jdk10   File: VSyncedBufferStrategyTest.java   View Source Code Vote up 5 votes
private void render(Graphics g) {
    g.setColor(Color.white);
    g.fillRect(0, 0, getWidth(), getHeight());

    g.setColor(Color.black);
    g.fillRect(blockX, blockY, BLOCK_W, BLOCK_H);
}
 
Example 15
Project: incubator-netbeans   File: DocumentSwitcherTable.java   View Source Code Vote up 5 votes
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
    if( null != color ) {
        g.setColor( color );
        g.fillRect( x, y, 5, height);
    }
}
 
Example 16
Project: openjdk-jdk10   File: SchemaTreeTraverser.java   View Source Code Vote up 5 votes
public final void paintComponent(Graphics g) {
    int width = this.getWidth();
    int height = this.getHeight();
    if (this.isSelected) {
        g.setColor(selectedBackground);
        g.fillRect(0, 0, width - 1, height - 1);
        g.setColor(selectedForeground);
        g.drawRect(0, 0, width - 1, height - 1);
    }
    super.paintComponent(g);
}
 
Example 17
Project: openjdk-jdk10   File: VolatileImageConfigurationTest.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g) {
    super.paint(g);

    g.setColor(Color.WHITE);
    g.fillRect(0, 0, PANEL_WIDTH, PANEL_HEIGHT);
    /* Display graphics configuration values of the component */
    drawInfo(g, PANEL_X, PANEL_Y, "Frame", Color.BLUE);
    int attempts = 0;
    do {
        /* Display graphics configuration values of volatile image */
        drawBackingStoreImage(g);
    } while (vImg.contentsLost() && ++attempts < 3);
}
 
Example 18
Project: openjdk-jdk10   File: NonOpaqueDestLCDAATest.java   View Source Code Vote up 5 votes
public void render(Graphics g, int w, int h) {
    initImages(w, h);

    g.setColor(new Color(0xAD, 0xD8, 0xE6));
    g.fillRect(0, 0, w, h);

    Graphics2D g2d = (Graphics2D) g.create();
    for (Image im : images) {
        g2d.drawImage(im, 0, 0, null);
        g2d.translate(0, im.getHeight(null));
    }
}
 
Example 19
Project: OpenJSharp   File: MotifIconFactory.java   View Source Code Vote up 4 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    // These variables are kind of pointless as the following code
    // assumes the icon will be 10 x 10 regardless of their value.
    int w = getIconWidth();
    int h = getIconHeight();

    Color oldColor = g.getColor();

    if (model.isSelected()){
        if( MotifGraphicsUtils.isLeftToRight(c) ){
            g.setColor(shadow);
            g.fillRect(x+1,y+1,2,h);
            g.drawLine(x+4,y+2,x+4,y+2);
            g.drawLine(x+6,y+3,x+6,y+3);
            g.drawLine(x+8,y+4,x+8,y+5);
            g.setColor(focus);
            g.fillRect(x+2,y+2,2,h-2);
            g.fillRect(x+4,y+3,2,h-4);
            g.fillRect(x+6,y+4,2,h-6);
            g.setColor(highlight);
            g.drawLine(x+2,y+h,x+2,y+h);
            g.drawLine(x+4,y+h-1,x+4,y+h-1);
            g.drawLine(x+6,y+h-2,x+6,y+h-2);
            g.drawLine(x+8,y+h-4,x+8,y+h-3);
        } else {
            g.setColor(highlight);
            g.fillRect(x+7,y+1,2,10);
            g.drawLine(x+5,y+9,x+5,y+9);
            g.drawLine(x+3,y+8,x+3,y+8);
            g.drawLine(x+1,y+6,x+1,y+7);
            g.setColor(focus);
            g.fillRect(x+6,y+2,2,8);
            g.fillRect(x+4,y+3,2,6);
            g.fillRect(x+2,y+4,2,4);
            g.setColor(shadow);
            g.drawLine(x+1,y+4,x+1,y+5);
            g.drawLine(x+3,y+3,x+3,y+3);
            g.drawLine(x+5,y+2,x+5,y+2);
            g.drawLine(x+7,y+1,x+7,y+1);
        }
    } else {
        if( MotifGraphicsUtils.isLeftToRight(c) ){
            g.setColor(highlight);
            g.drawLine(x+1,y+1,x+1,y+h);
            g.drawLine(x+2,y+1,x+2,y+h-2);
            g.fillRect(x+3,y+2,2,2);
            g.fillRect(x+5,y+3,2,2);
            g.fillRect(x+7,y+4,2,2);
            g.setColor(shadow);
            g.drawLine(x+2,y+h-1,x+2,y+h);
            g.fillRect(x+3,y+h-2,2,2);
            g.fillRect(x+5,y+h-3,2,2);
            g.fillRect(x+7,y+h-4,2,2);
            g.setColor(oldColor);
        } else {
            g.setColor(highlight);
            g.fillRect(x+1,y+4,2,2);
            g.fillRect(x+3,y+3,2,2);
            g.fillRect(x+5,y+2,2,2);
            g.drawLine(x+7,y+1,x+7,y+2);
            g.setColor(shadow);
            g.fillRect(x+1,y+h-4,2,2);
            g.fillRect(x+3,y+h-3,2,2);
            g.fillRect(x+5,y+h-2,2,2);
            g.drawLine(x+7,y+3,x+7,y+h);
            g.drawLine(x+8,y+1,x+8,y+h);
            g.setColor(oldColor);
        }
    }

}
 
Example 20
Project: jdk8u-jdk   File: DefaultTreeCellRenderer.java   View Source Code Vote up 4 votes
/**
  * Paints the value.  The background is filled based on selected.
  */
public void paint(Graphics g) {
    Color bColor;

    if (isDropCell) {
        bColor = DefaultLookup.getColor(this, ui, "Tree.dropCellBackground");
        if (bColor == null) {
            bColor = getBackgroundSelectionColor();
        }
    } else if (selected) {
        bColor = getBackgroundSelectionColor();
    } else {
        bColor = getBackgroundNonSelectionColor();
        if (bColor == null) {
            bColor = getBackground();
        }
    }

    int imageOffset = -1;
    if (bColor != null && fillBackground) {
        imageOffset = getLabelStart();
        g.setColor(bColor);
        if(getComponentOrientation().isLeftToRight()) {
            g.fillRect(imageOffset, 0, getWidth() - imageOffset,
                       getHeight());
        } else {
            g.fillRect(0, 0, getWidth() - imageOffset,
                       getHeight());
        }
    }

    if (hasFocus) {
        if (drawsFocusBorderAroundIcon) {
            imageOffset = 0;
        }
        else if (imageOffset == -1) {
            imageOffset = getLabelStart();
        }
        if(getComponentOrientation().isLeftToRight()) {
            paintFocus(g, imageOffset, 0, getWidth() - imageOffset,
                       getHeight(), bColor);
        } else {
            paintFocus(g, 0, 0, getWidth() - imageOffset, getHeight(), bColor);
        }
    }
    super.paint(g);
}