本文整理汇总了Java中java.awt.Graphics2D.drawRect方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.drawRect方法的具体用法?Java Graphics2D.drawRect怎么用?Java Graphics2D.drawRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.drawRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintBorder
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the component border.
*
* @param graphics
* the graphics context
*/
void paintBorder(Graphics graphics) {
Graphics2D g = (Graphics2D) graphics.create();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Colors.BUTTON_BORDER);
int radius = RapidLookAndFeel.CORNER_DEFAULT_RADIUS;
switch (position) {
case SwingConstants.LEFT:
g.drawRoundRect(0, 0, button.getWidth() + radius, button.getHeight() - 1, radius, radius);
break;
case SwingConstants.CENTER:
g.drawRect(0, 0, button.getWidth() + radius, button.getHeight() - 1);
break;
default:
g.drawRoundRect(-radius, 0, button.getWidth() + radius - 1, button.getHeight() - 1, radius, radius);
g.drawLine(0, 0, 0, button.getHeight());
break;
}
}
示例2: drawTileName
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage drawTileName(BufferedImage image, String name) {
BufferedImage i2 = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = i2.createGraphics();
g2.drawImage(image, null, 0, 0);
g2.setColor(Color.red);
g2.setStroke(new BasicStroke(4));
g2.drawRect(8, 8, image.getWidth() - 8, image.getHeight() - 8);
g2.setColor(Color.RED);
g2.setFont(g2.getFont().deriveFont(Font.BOLD).deriveFont(13f));
FontMetrics fm = g2.getFontMetrics();
String[] parts = name.split("/");
for (int i = 0; i < parts.length; i++) {
String s = i == parts.length - 1 ? parts[i] : parts[i] + "/";
int x = 40 + i * 5;
int y = 40 + i * (fm.getHeight() + 5);
Rectangle2D rect = fm.getStringBounds(s, g2);
g2.setColor(Color.white);
g2.fillRect(x, y - fm.getAscent(), (int)rect.getWidth(), fm.getHeight());
g2.setColor(Color.red);
g2.drawString(s, x, y);
}
return i2;
}
示例3: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g1d) {
Graphics2D g = (Graphics2D) g1d;
g.setPaint(background);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(Color.yellow);
g.drawRect(0,0,width,height);
if (image != null) {
g.drawImage(image, 0, 0, null);
}
g.setColor(Color.green);
for (int i=0;i<selected.size();i++) {
Sprite sprite = (Sprite) selected.get(i);
g.drawRect(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight());
}
}
示例4: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = Utils.prepareGraphics( g );
if( showBorder && !Utils.isDefaultButtons() ) {
Border b = underline ? mouseoverBorder : regularBorder;
b.paintBorder(this, g, 0, 0, getWidth(), getHeight());
}
super.paintComponent(g2);
if( showBorder && Utils.isDefaultButtons() )
return;
Dimension size = getSize();
if( hasFocus() && isEnabled() ) {
g2.setStroke( LINK_IN_FOCUS_STROKE );
g2.setColor( Utils.getFocusedLinkColor() );
g2.drawRect( 0, 0, size.width - 1, size.height - 1 );
}
}
示例5: paintIcon
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setColor(Color.WHITE);
g2d.fillRect(x + 1, y + 1, width - 2, height - 2);
g2d.setColor(Color.BLACK);
g2d.drawRect(x + 1, y + 1, width - 2, height - 2);
g2d.setColor(Color.RED);
g2d.setStroke(stroke);
g2d.drawLine(x + 10, y + 10, x + width - 10, y + height - 10);
g2d.drawLine(x + 10, y + height - 10, x + width - 10, y + 10);
g2d.dispose();
}
示例6: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
Dimension d = getPreferredSize();
g.setColor(Color.black);
g.drawRect( 0, 0, d.width - 1, d.height - 1 );
g.setColor(backgroundC);
g.fillRect( 1, 1, d.width - 2, d.height - 2 );
g.setFont(new Font("SansSerif", Font.PLAIN, 9));
Enumeration photoDepthList = photosAtDepths.keys();
g.setColor(Color.black);
int i = 0;
while ( photoDepthList.hasMoreElements() ) {
double depth = Double.parseDouble((String)photoDepthList.nextElement());
int y = (int)( ( depth ) * zScale );
// if ( cores[i].recovered > 0 ) {
// y += (int)( ( cores[i].recovered * 0.5 ) * zScale );
// }
g.fillOval( 7, y, 6, 6);
i++;
}
prevAge = -1;
}
示例7: paintBorder
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
int thick = getThickness();
if (!(g instanceof Graphics2D)) {
return;
}
Graphics2D g2d = (Graphics2D)g.create();
if (thick >= 1) {
g2d.setColor(this.lineColor);
int x2 = x + width - ((thick +1) / 2);
g2d.drawLine(x2 - SIDEBAR_GAP_WIDTH,
0, x2 - SIDEBAR_GAP_WIDTH, y + height - 1);
}
g2d.setColor(textBkColor);
int gap = width - SIDEBAR_GAP_WIDTH;
g2d.drawRect(gap, 0, width - gap, height);
}
示例8: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics g, Map map) {
if (selection != null) {
final Graphics2D g2d = (Graphics2D) g;
final Stroke str = g2d.getStroke();
g2d.setStroke(new BasicStroke(thickness));
g2d.setColor(color);
g2d.drawRect(selection.x, selection.y, selection.width, selection.height);
g2d.setStroke(str);
}
}
示例9: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(final Graphics g) {
final Graphics2D g2d = (Graphics2D) g;
// background
g2d.setPaint(lpg);
g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
g2d.setColor(Color.BLACK);
// border
g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
示例10: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = prepareGraphics( g );
super.paintComponent(g2);
Dimension size = getSize();
if( hasFocus() && isEnabled() ) {
g2.setStroke( LINK_IN_FOCUS_STROKE );
g2.setColor( linkInFocusColor );
g2.drawRect( 0, 0, size.width - 1, size.height - 1 );
}
}
示例11: drawOpenSpotAtEndOfMenuBar
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawOpenSpotAtEndOfMenuBar(Graphics2D g2, JComponent mb) {
Point mblocation = SwingUtilities.convertPoint(mb, new Point(0,0), this);
if(mb.getComponentCount() > 0) {
Component lastComp = mb.getComponent(mb.getComponentCount()-1);
mblocation.x += lastComp.getX() + lastComp.getWidth();
}
g2.drawRect(mblocation.x+2, mblocation.y+2, mb.getHeight()-4, mb.getHeight()-4);
}
示例12: featherDragImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
private BufferedImage featherDragImage(BufferedImage src,
int w, int h, int b) {
// FIXME: duplicated from PieceMover!
final BufferedImage dst =
ImageUtils.createCompatibleTranslucentImage(w, h);
final Graphics2D g = dst.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// paint the rectangle occupied by the piece at specified alpha
g.setColor(new Color(0xff, 0xff, 0xff, CURSOR_ALPHA));
g.fillRect(0, 0, w, h);
// feather outwards
for (int f = 0; f < b; ++f) {
final int alpha = CURSOR_ALPHA * (f + 1) / b;
g.setColor(new Color(0xff, 0xff, 0xff, alpha));
g.drawRect(f, f, w-2*f, h-2*f);
}
// paint in the source image
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN));
g.drawImage(src, 0, 0, null);
g.dispose();
return dst;
}
示例13: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
if (img == null) {
g2.setColor(Color.BLACK);
String err = "Failed to load image";
int wos = EZElement.getWidthOf(err);
int hos = EZElement.getHeightOf(err);
g2.drawRect((int) xCenter - wos / 2 - 10, (int) yCenter - hos / 2 - 10, wos + 20, hos + 20);
g2.drawString(err, (int) xCenter - wos / 2, (int) yCenter);
}
else {
AffineTransform tmp = g2.getTransform();
g2.setTransform(EZElement.transformHelper(this));
if(imgHasFocus) {
g2.drawImage(img,
-(xbrf - xtlf)/2, -(ybrf-ytlf)/2,
(xbrf - xtlf)/2, (ybrf-ytlf)/2,
xtlf, ytlf,
xbrf, ybrf, null);
}
else {
g2.drawImage(img, -img.getWidth() / 2, -img.getHeight() / 2, null);
}
g2.setTransform(tmp);
}
}
}
示例14: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.ORANGE);
g2.setStroke(new BasicStroke(2));
if (x1 < x2) {
int width = x2 - x1;
int height = y2 - y1;
int xCell = width / 8;
int yCell = height / 8;
int xDif = xCell;
int yDif = yCell;
for(int i = 0; i < 7; i++){
g2.drawLine(x1, y1 + yCell, x2, y2 - height + yCell);
g2.drawLine(x1 + xCell, y1, x2 - width + xCell, y2);
yCell += yDif;
xCell += xDif;
}
g2.drawRect(x1, y1, x2 - x1, y2 - y1);
}
}
示例15: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint( Object oa, Graphics2D g2, PanMouseAdaptor ma ) {
ColorRGBA col = (ColorRGBA)oa;
int r = (int)(col.r * 255),
g = (int)(col.g * 255),
b = (int)(col.b * 255);
float[] hsb = Color.RGBtoHSB( r,g,b, null );
g2.setColor(new Color(r,g,b) );
g2.drawRect( ma.toX( hsb[0] * 10), ma.toY( hsb[2] * 10), ma.toZoom( 0.1 ), ma.toZoom( 0.1 ) );
}