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


Java Graphics2D.drawRect方法代码示例

本文整理汇总了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;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:27,代码来源:CompositeButtonPainter.java

示例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;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:25,代码来源:MMapServer.java

示例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());
	}
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:23,代码来源:SheetPanel.java

示例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 );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:LinkButton.java

示例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();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:MissingIcon.java

示例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;
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:24,代码来源:PhotoDisplay.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CustomizableSideBar.java

示例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);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:11,代码来源:KeyBufferer.java

示例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);
}
 
开发者ID:CoffeeCodeSwitzerland,项目名称:Lernkartei_2017,代码行数:12,代码来源:Push.java

示例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 );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:LinkButton.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:DropTargetLayer.java

示例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;
    }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:29,代码来源:SetupStack.java

示例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);
    }
  }
}
 
开发者ID:gcalica,项目名称:agar.io,代码行数:28,代码来源:EZ.java

示例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);
    }
}
 
开发者ID:mhusam,项目名称:ChessBot,代码行数:31,代码来源:ChessDrawerWindow.java

示例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 )  );
	
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:17,代码来源:ColorRGBAPainter.java


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