当前位置: 首页>>代码示例>>Java>>正文


Java Graphics.fillRect方法代码示例

本文整理汇总了Java中java.awt.Graphics.fillRect方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.fillRect方法的具体用法?Java Graphics.fillRect怎么用?Java Graphics.fillRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics的用法示例。


在下文中一共展示了Graphics.fillRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ColorCellEditor

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:22,代码来源:ColorCellEditor.java

示例2: createTestImage

import java.awt.Graphics; //导入方法依赖的package包/类
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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:EncodeSubImageTest.java

示例3: colorBlack

import java.awt.Graphics; //导入方法依赖的package包/类
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);
}
 
开发者ID:QuantumSoundings,项目名称:BassNES,代码行数:25,代码来源:Visualizer.java

示例4: ImageGenerator

import java.awt.Graphics; //导入方法依赖的package包/类
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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:ImageGenerator.java

示例5: disegna

import java.awt.Graphics; //导入方法依赖的package包/类
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;
}
 
开发者ID:AhabHyde,项目名称:NeuralNet,代码行数:24,代码来源:JTela.java

示例6: initVI

import java.awt.Graphics; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:AcceleratedScaleTest.java

示例7: drawBars

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:25,代码来源:BarChartComponent.java

示例8: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ImagePanel.java

示例9: draw

import java.awt.Graphics; //导入方法依赖的package包/类
public void draw(Graphics g)
{
   g.setColor(getColor());
   
   if (isFilled())
      g.fillRect(getUpperLeftX(), getUpperLeftY(),
         getWidth(), getHeight());
   else
      g.drawRect(getUpperLeftX(), getUpperLeftY(),
         getWidth(), getHeight());
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:12,代码来源:MyRect.java

示例10: paintSelectedValue

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:47,代码来源:FastGraph.java

示例11: drawPreviewStrategyWithName

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:KodeMunkie,项目名称:imagetozxspec,代码行数:18,代码来源:PreviewLabeller.java

示例12: doPaint

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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);
        }
    }

}
 
开发者ID:etomica,项目名称:etomica,代码行数:38,代码来源:DisplayPolytopeCanvas2D.java

示例13: drawRect

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 绘制方形
 */
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
}
 
开发者ID:ajtdnyy,项目名称:ScreenCut,代码行数:11,代码来源:ScreenCut.java

示例14: render

import java.awt.Graphics; //导入方法依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:VSyncedBufferStrategyTest.java

示例15: paintBorder

import java.awt.Graphics; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:DocumentSwitcherTable.java


注:本文中的java.awt.Graphics.fillRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。