本文整理汇总了Java中java.awt.Graphics.clearRect方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.clearRect方法的具体用法?Java Graphics.clearRect怎么用?Java Graphics.clearRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics
的用法示例。
在下文中一共展示了Graphics.clearRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paint
import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g) {
Rectangle b = getVisibleRect();
g.clearRect(b.x, b.y, b.width, b.height);
myBoard.draw(g, 0, 0, 1.0, this);
final Rectangle bounds =
new Rectangle(new Point(),myBoard.bounds().getSize());
grid.forceDraw(g,bounds,bounds,1.0,false);
final Rectangle selection = config.getSelectionRect();
if (selection != null) {
final Graphics2D g2d = (Graphics2D) g;
final Stroke str = g2d.getStroke();
g2d.setStroke(new BasicStroke(2.0f));
g2d.setColor(Color.RED);
g2d.drawRect(selection.x, selection.y, selection.width, selection.height);
g2d.setStroke(str);
}
}
示例2: Visualizer
import java.awt.Graphics; //导入方法依赖的package包/类
public Visualizer(Visualizable obs) {
observer = obs;
setBorder(BorderFactory.createLineBorder(Color.black));
visPanel = new JPanel() {
private static final long serialVersionUID = 1L;
public void paint(Graphics g) {
g.clearRect(0, 0, observer.getVisualizerWidth(), observer.getVisualizerHeight());
g.drawImage(observer.getVisualizerImage(), 0, 0, this);
}
};
add(visPanel, BorderLayout.CENTER);
}
示例3: draw
import java.awt.Graphics; //导入方法依赖的package包/类
public void draw(int healthLevel) {
int squareW = this.getWidth();
int squareH = this.getHeight()-2;
int squareX = 0;
int squareY = 0;
int widthX = (int)((double)squareW / (double)(Player.healthLevelScaling*2));
Graphics g = this.getGraphics();
g.clearRect(0, 0, squareW, squareH);
g.setColor(getColorForHealth(healthLevel));
for(int i = 0; i<healthLevel;i++){
g.fillRect(squareX+ i * widthX +2 , squareY, widthX, squareH);
}
g.setColor(Color.BLACK);
for(int j =0; j <Player.healthLevelScaling*2;j++) {
g.drawRect(squareX+ j * widthX, squareY, widthX-2, squareH);
}
}
示例4: paintBackground
import java.awt.Graphics; //导入方法依赖的package包/类
protected void paintBackground(Graphics g) {
if (AppPreferences.ANTI_ALIASING.getBoolean()) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
g.clearRect(0, 0, getWidth(), getHeight());
}
示例5: drawImageToBuffer
import java.awt.Graphics; //导入方法依赖的package包/类
static int[] drawImageToBuffer(Object gOffscreen, Object imageOffscreen,
Object imageobj, int width, int height,
int bgcolor) {
Graphics g = (Graphics) gOffscreen;
java.awt.Image image = (java.awt.Image) imageobj;
int width0 = image.getWidth(null);
int height0 = image.getHeight(null);
if (g instanceof Graphics2D) {
((Graphics2D) g).setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_IN, 1.0f));
g.setColor(bgcolor == 0 ? new Color(0, 0, 0, 0) : new Color(bgcolor));
g.fillRect(0, 0, width, height);
((Graphics2D) g).setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 1.0f));
g.drawImage(image, 0, 0, width, height, 0, 0, width0, height0, null);
} else {
g.clearRect(0, 0, width, height);
g.drawImage(image, 0, 0, width, height, 0, 0, width0, height0, null);
}
return grabPixels(imageOffscreen, width, height, null, 0, 0);
}
示例6: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
final int w = getWidth();
final int h = getHeight();
g.clearRect(0, 0, w, h);
g.setColor(Color.BLACK);
float widthPerBar = w / (float)xResolution;
float startX = 0;
synchronized(this){
totalValue = 0;
for(int i = 0; i < xResolution; ++i){
float endX = startX + widthPerBar;
float v = values.get(i);
totalValue += v;
float height = v * h;
g.fillRect((int)startX, h - (int)height, (int)widthPerBar, (int)height);
startX = endX;
}
}
}
示例7: paintIcon
import java.awt.Graphics; //导入方法依赖的package包/类
public void paintIcon(Component c, Graphics g, int x, int y) {
if (board != null) {
board.draw(g,x,y,picker.getSlotScale(), c);
}
else {
g.clearRect(x,y,getIconWidth(),getIconHeight());
}
}
示例8: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
Dimension d = ((Component)target).getSize();
if (g instanceof Graphics2D ||
g instanceof sun.awt.Graphics2Delegate) {
// background color is setup correctly, so just use clearRect
g.clearRect(0, 0, d.width, d.height);
} else {
// emulate clearRect
g.setColor(((Component)target).getBackground());
g.fillRect(0, 0, d.width, d.height);
g.setColor(((Component)target).getForeground());
}
super.paint(g);
}
示例9: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
final int w = getWidth();
final int h = getHeight();
g.clearRect(0, 0, w, h);
g.setColor( Color.BLUE );
final int mi = M.min(w, dataLenght);
for(int i = 0; i < mi; ++i){
final int iy = bufferData[i] * h / 128;
g.drawRect(i, iy, 1, 1);
}
}
示例10: paint
import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g){
int d = dimension;
Image img1 = Toolkit.getDefaultToolkit().getImage("src/pic_queen.png");
g.setColor(new Color(255, 189, 35));
g.fillRect(margin, margin, dim, dim);
if(d == 1)
g.drawImage(img1, margin, margin, size, size , null , this);
else{
for(int i = margin; i < dim + margin; i+=2*size){
for(int j = margin; j < dim + margin; j+=2*size){
g.clearRect(i, j, size, size);
}
}
for(int i = margin+size; i < dim + margin; i+=2*size){
for(int j = margin + size; j < dim + margin; j+=2*size){
g.clearRect(i, j, size, size);
}
}
}
for(int i = 0; i < d; i++)
for(int j = 0; j < d; j++)
if(t[i][j] == 'Q')
g.drawImage(img1, margin + i*size, margin + j * size, size, size , null , this);
}
示例11: paintComponent
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
if (AppPreferences.ANTI_ALIASING.getBoolean()) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
g.clearRect(0, 0, getWidth(), getHeight());
CanvasTool current = canvas.getTool();
for (int i = 0; i < tools.length; i++) {
AbstractTool[] column = tools[i];
int x = ICON_SEP + i * (ICON_SEP + ICON_WIDTH);
int y = ICON_SEP;
for (int j = 0; j < column.length; j++) {
AbstractTool tool = column[j];
if (tool == listener.toolPressed && listener.inTool) {
g.setColor(Color.darkGray);
g.fillRect(x, y, ICON_WIDTH, ICON_HEIGHT);
}
Icon icon = tool.getIcon();
if (icon != null)
icon.paintIcon(this, g, x, y);
if (tool == current) {
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.black);
g.drawRect(x - 1, y - 1, ICON_WIDTH + 2, ICON_HEIGHT + 2);
}
y += ICON_HEIGHT + ICON_SEP;
}
}
g.setColor(Color.black);
GraphicsUtil.switchToWidth(g, 1);
}
示例12: PaintFlightLog
import java.awt.Graphics; //导入方法依赖的package包/类
private void PaintFlightLog(Graphics g)
{
int paintsCount = -1;
int textSize = 0;
for(int i = 0; i < window.paintText.size(); i++)
for(int k = 0; k < window.paintText.get(i).split("\n").length; k++)
textSize++;
g.clearRect(0, 0, window.button_abort.getBounds().x-1, getHeight());
for(int i = 0; i < window.paintText.size(); i++)
{
String text = window.paintText.get(i);
if(text.substring(0, 5).equals("ALERT")) g.setColor(Color.RED);
String[] texts = text.split("\n");
for(int k = 0; k < texts.length; k++)
{
paintsCount++;
g.drawString(texts[k], window.paintStartPos.width, getHeight() - (window.paintStartPos.height + window.paintDistance*(textSize -paintsCount)));
}
g.setColor(Color.BLACK);
}
}
示例13: update
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void update(Graphics g) {
if (backBuffer == null) {
g.clearRect(0, 0, getSize().width, getSize().height);
}
paint(g);
}
示例14: initContents
import java.awt.Graphics; //导入方法依赖的package包/类
/**
* Set contents of the current SurfaceData to default state (i.e. clear
* the background).
*/
public void initContents() {
// images with forced acceleration type may have a null sdCurrent
// because we do not create a backup surface for them
if (sdCurrent != null) {
Graphics g = vImg.createGraphics();
g.clearRect(0, 0, vImg.getWidth(), vImg.getHeight());
g.dispose();
}
}
示例15: paint
import java.awt.Graphics; //导入方法依赖的package包/类
/**
* Invokes paint and update on target Component with optimal
* rectangular clip region.
* If PAINT bounding rectangle is less than
* MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
* painted separately. Otherwise the entire bounding rectangle is painted.
*
* @param target Component to {@code paint} or {@code update}
* @since 1.4
*/
public void paint(Object target, boolean shouldClearRectBeforePaint) {
Component comp = (Component)target;
if (isEmpty()) {
return;
}
if (!comp.isVisible()) {
return;
}
RepaintArea ra = this.cloneAndReset();
if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
}
if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
int square = paintRect.width * paintRect.height;
int benefit = square - ra.paintRects[HORIZONTAL].width
* ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
* ra.paintRects[VERTICAL].height;
// if benefit is comparable with bounding box
if (MAX_BENEFIT_RATIO * benefit < square) {
ra.paintRects[HORIZONTAL] = paintRect;
ra.paintRects[VERTICAL] = null;
}
}
for (int i = 0; i < paintRects.length; i++) {
if (ra.paintRects[i] != null
&& !ra.paintRects[i].isEmpty())
{
// Should use separate Graphics for each paint() call,
// since paint() can change Graphics state for next call.
Graphics g = comp.getGraphics();
if (g != null) {
try {
g.setClip(ra.paintRects[i]);
if (i == UPDATE) {
updateComponent(comp, g);
} else {
if (shouldClearRectBeforePaint) {
g.clearRect( ra.paintRects[i].x,
ra.paintRects[i].y,
ra.paintRects[i].width,
ra.paintRects[i].height);
}
paintComponent(comp, g);
}
} finally {
g.dispose();
}
}
}
}
}