本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}
}
}
示例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
}
示例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);
}
示例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);
}
}