當前位置: 首頁>>代碼示例>>Java>>正文


Java Graphics.drawRect方法代碼示例

本文整理匯總了Java中java.awt.Graphics.drawRect方法的典型用法代碼示例。如果您正苦於以下問題:Java Graphics.drawRect方法的具體用法?Java Graphics.drawRect怎麽用?Java Graphics.drawRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Graphics的用法示例。


在下文中一共展示了Graphics.drawRect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: paint

import java.awt.Graphics; //導入方法依賴的package包/類
@Override
public void paint(Graphics g) {
	if (zoomming) {
		g.setColor(Color.BLUE);
		if (xStart < xEnd && yStart < yEnd) {
			g.drawRect(xStart, yStart, xEnd - xStart, yEnd - yStart);
		}
		if (xStart < xEnd && yStart > yEnd) {
			g.drawRect(xStart, yEnd, xEnd - xStart, yStart - yEnd);
		}
		if (xStart > xEnd && yStart < yEnd) {
			g.drawRect(xEnd, yStart, xStart - xEnd, yEnd - yStart);
		}
		if (xStart > xEnd && yStart > yEnd) {
			g.drawRect(xEnd, yEnd, xStart - xEnd, yStart - yEnd);
		}
	}
}
 
開發者ID:max6cn,項目名稱:jmt,代碼行數:19,代碼來源:KFuzzyScatter.java

示例2: paintBorder

import java.awt.Graphics; //導入方法依賴的package包/類
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
    g.translate( x, y );

    g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
    g.drawRect( 0, 0, w - 1, h - 1 );

    g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
    g.drawLine( 1, 1, w - 2, 1 );
    g.drawLine( 1, 2, 1, 2 );
    g.drawLine( 1, h - 2, 1, h - 2 );

    g.translate( -x, -y );

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:MetalBorders.java

示例3: paintComponent

import java.awt.Graphics; //導入方法依賴的package包/類
@Override
protected void paintComponent(Graphics g) {

	// TODO: Give "priorities" and always pick color of a notice with
	// highest priority (e.g. parsing errors will usually be red).

	Color borderColor = getColor();
	if (borderColor==null) {
		borderColor = Color.DARK_GRAY;
	}
	Color fillColor = getBrighterColor(borderColor);

	int w = getWidth();
	int h = getHeight();

	g.setColor(fillColor);
	g.fillRect(0,0, w,h);

	g.setColor(borderColor);
	g.drawRect(0,0, w-1,h-1);

}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:23,代碼來源:ErrorStrip.java

示例4: paint

import java.awt.Graphics; //導入方法依賴的package包/類
@Override public void paint(Graphics graphics) {
	graphics.setColor(Color.BLACK);
	((Graphics2D)graphics).draw(shape);
	graphics.setFont(graphics.getFont().deriveFont(10f));
	graphics.drawString("ALU", 30, 14);
	graphics.drawString("74181", 25, 30);
	graphics.setFont(graphics.getFont().deriveFont(8f));
	graphics.drawString("M", 10, 56);
	graphics.drawString("Cn", 10, 64);
	graphics.drawString("P", size.width-14, 20);
	graphics.drawString("G", size.width-14, 28);
	graphics.drawString("Cn+4", size.width-28, 46);
	graphics.drawString("A=B", size.width-24, 64);
	for(int number=0;number<=3;number++) {
		int top = 75+number*20;
		graphics.drawRect(5, top, size.width-10, 20);
		graphics.drawString("A"+number, 11, top+8);
		graphics.drawString("B"+number, 11, top+18);
		graphics.drawString("S"+number, 10, 12+number*10);
		graphics.drawString("F"+number, size.width-18, top+13);
	}
	ContactUtilities.paintSolderingJoints(graphics, contacts);
}
 
開發者ID:kristian,項目名稱:JDigitalSimulator,代碼行數:24,代碼來源:ALU74181.java

示例5: show

import java.awt.Graphics; //導入方法依賴的package包/類
private void show(String title) {
    Frame frame = new Frame() {

        @Override
        public void paint(Graphics g) {
            super.paint(g);
            g.drawImage(buffImage, 0, 0, this);
            g.setColor(Color.GRAY);
            g.drawRect(0, 0, width, height);
            g.drawRect(0, height / 2, width, height / 2);
            g.drawRect(width / 2, 0, width / 2, height);
        }
    };
    frame.setTitle(title);
    frame.setSize(width, height);
    frame.setVisible(true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:MultiResolutionDrawImageWithTransformTest.java

示例6: paintComponent

import java.awt.Graphics; //導入方法依賴的package包/類
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (focused) {
        Color bdr = UIManager.getColor("Tree.selectionBorderColor"); //NOI18N

        if (bdr == null) {
            //Button focus color doesn't work on win classic - better to
            //get the color from a value we know will work - Tim
            if (getForeground().equals(Color.BLACK)) { //typical
                bdr = getBackground().darker();
            } else {
                bdr = getForeground().darker();
            }
        }

        g.setColor(bdr);
        g.drawRect(1, 1, getWidth() - 3, getHeight() - 3);
        g.setColor(bdr);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:TableSheetCell.java

示例7: paintIcon

import java.awt.Graphics; //導入方法依賴的package包/類
public void paintIcon(Component c, Graphics g, int x, int y) {
  g.setColor(Color.black);
  g.drawRect(x, y, swatchWidth-1, swatchHeight-1);

  if (color != null) {
    g.setColor(color);
    g.fillRect(x+1, y+1, swatchWidth-2, swatchHeight-2);
  }
  else {
    // paint no color and a "nil" if the color is null
    g.setColor(UIManager.getColor("controlText"));
    g.setFont(FONT);
    g.drawString("nil",
      x+(swatchWidth - g.getFontMetrics(FONT).stringWidth("nil"))/ 2,
      y+(swatchHeight + g.getFontMetrics(FONT).getAscent())/2);
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:18,代碼來源:ColorButton.java

示例8: drawGroove

import java.awt.Graphics; //導入方法依賴的package包/類
public static void drawGroove(Graphics g, int x, int y, int w, int h,
                              Color shadow, Color highlight)
{
    Color oldColor = g.getColor();  // Make no net change to g
    g.translate(x, y);

    g.setColor(shadow);
    g.drawRect(0, 0, w-2, h-2);

    g.setColor(highlight);
    g.drawLine(1, h-3, 1, 1);
    g.drawLine(1, 1, w-3, 1);

    g.drawLine(0, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 0);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:MotifGraphicsUtils.java

示例9: paintIcon

import java.awt.Graphics; //導入方法依賴的package包/類
@Override public void paintIcon(Component c, Graphics g, int x, int y)
{
    g.setColor(color);
    g.fillRect(x, y, size, size);
    g.setColor(Color.DARK_GRAY);
    g.drawRect(x, y, size-1, size-1);
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:8,代碼來源:CarDialog.java

示例10: drawRocketWithBrakes

import java.awt.Graphics; //導入方法依賴的package包/類
private void drawRocketWithBrakes(Graphics g, int startX,int startY, int rW, int rH, int bDist, int bW, int bH)
{
	g.drawOval(startX - rW, startY - rH, 2*rW, 2*rH);
	
	if(window.telemetry_booster_brakes[1])	//left
		g.fillRect(startX - rW - bDist - 2*bH, startY - bW, 2*bH, 2*bW);
	else g.drawRect(startX - rW - bDist - 2*bH, startY - bW, 2*bH, 2*bW);
	
	if(window.telemetry_booster_brakes[0])	//top
		g.fillRect(startX - bW, startY - rH - bDist - 2*bH, 2*bW, 2*bH);
	else g.drawRect(startX - bW, startY - rH - bDist - 2*bH, 2*bW, 2*bH);
	
	if(window.telemetry_booster_brakes[3])	//right
		g.fillRect(startX + rW + bDist, startY - bW, 2*bH, 2*bW);
	else g.drawRect(startX + rW + bDist, startY - bW, 2*bH, 2*bW);
	
	if(window.telemetry_booster_brakes[2])	//bottom
		g.fillRect(startX - bW, startY + rH + bDist, 2*bW, 2*bH);
	else g.drawRect(startX - bW, startY + rH + bDist, 2*bW, 2*bH);	
}
 
開發者ID:janw23,項目名稱:New-Kepard,代碼行數:21,代碼來源:JWindow.java

示例11: paint

import java.awt.Graphics; //導入方法依賴的package包/類
public void paint(Graphics g)
{
	g.drawRect(10, 10, 450, 400);
	g.drawLine(10, 210, 460, 210);
	switch(flag)
	{
		case 1:
			//sin
			for(int i = 10; i < 370; i++)
			{
				x = i;
				y = 210 - (int)(100*Math.sin((x-10)*Math.PI/180.0));
				g.drawLine(x, y, x, y);
			}
			break;
		case 2:
			//cos
			for(int i = 10; i < 370; i++)
			{
				x = i;
				y = 210 - (int)(100*Math.cos((x-10)*Math.PI/180.0));
				g.drawLine(x, y, x, y);
			}
			break;
		default:
			break;
	
	}
}
 
開發者ID:pwn-orz,項目名稱:anti-fanmei,代碼行數:30,代碼來源:FunPlot.java

示例12: paint

import java.awt.Graphics; //導入方法依賴的package包/類
@Override
public void paint(Graphics g) {
	determinePreferredSize();
	super.paint(g);

	if (this.filePane.fc.isMultiSelectionEnabled()) {
		if (this.pointChanged) {
			if (this.mpcx < 0) {
				this.tx = this.mpcx + this.mpx;
				this.mpcx *= -1;
			} else {
				this.tx = this.mpx;
			}

			if (this.mpcy < 0) {
				this.ty = this.mpcy + this.mpy;
				this.mpcy *= -1;
			} else {
				this.ty = this.mpy;
			}
			this.pointChanged = false;
		}

		this.selectionRect = new Rectangle(this.tx, this.ty, this.mpcx, this.mpcy);

		if (this.mouseDownFlag) {

			g.setColor(new Color(RapidLookTools.getColors().getFileChooserColors()[0].getRed(), RapidLookTools
					.getColors().getFileChooserColors()[0].getGreen(),
					RapidLookTools.getColors().getFileChooserColors()[0].getBlue(), 40));
			g.fillRect(this.tx, this.ty, this.mpcx, this.mpcy);

			g.setColor(RapidLookTools.getColors().getFileChooserColors()[0]);
			g.drawRect(this.tx, this.ty, this.mpcx, this.mpcy);

			updateSelectionsForDrag();

		}
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:41,代碼來源:ItemPanel.java

示例13: paint

import java.awt.Graphics; //導入方法依賴的package包/類
/**
 * Draws an indicator that the caret is being selected. Here, we'll draw a red
 * rectangle around the value.
 */
@Override
public void paint(InstancePainter painter) {
	Bounds bds = painter.getBounds();
	BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
	int len = (width.getWidth() + 3) / 4;

	Graphics g = painter.getGraphics();
	g.setColor(Color.RED);
	int wid = 7 * len + 2; // width of caret rectangle
	int ht = 16; // height of caret rectangle
	g.drawRect(bds.getX() + (bds.getWidth() - wid) / 2, bds.getY() + (bds.getHeight() - ht) / 2, wid, ht);
	g.setColor(Color.BLACK);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:18,代碼來源:CounterPoker.java

示例14: paintComponent

import java.awt.Graphics; //導入方法依賴的package包/類
@Override
	public void paintComponent(Graphics g) {
		double[] x = model.getListObservations();
		
		super.paintComponent(g);
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, 202, 202);
		//Draw Border
		g.setColor(Color.BLACK);
		g.drawRect(0, 0, 202, 202);
		//Draw gray lines\
		Graphics2D g1 = (Graphics2D) g;
		g1.setColor(Color.LIGHT_GRAY);
		for (int i = 1; i < 9; i++) {
			g1.drawLine(1, 1 + (i * (202 / 9)), 201, 1 + (i * (202 / 9)));
			g1.drawLine(1 + (i * (202 / 9)), 1, 1 + (i * (202 / 9)), 202);
		}
		g1.setColor(Color.BLACK);
		for (int i = 1; i < 9; i++) {
			g1.drawLine(1, 1 + (i * (202 / 9)), 6, 1 + (i * (202 / 9)));
			g1.drawLine(1 + (i * (202 / 9)), 1, 1 + (i * (202 / 9)), 6);
			g1.drawLine(197, 1 + (i * (202 / 9)), 202, 1 + (i * (202 / 9)));
			g1.drawLine(1 + (i * (202 / 9)), 198, 1 + (i * (202 / 9)), 202);
		}
	
		//Draw graph
		//Draw reference line
		g.setColor(Color.BLUE);
		for (int i = 0; i < x.length; i++) {
			g.fillOval((int) Math.round((x[i] / x[x.length-1]) * 200),
					200 - (int) Math.round((i*(1d/x.length)) * 200), 5, 5);
		}
		
		//g.fillOval(200,1, 5, 5);

}
 
開發者ID:max6cn,項目名稱:jmt,代碼行數:37,代碼來源:SmallCDF.java

示例15: paintIcon

import java.awt.Graphics; //導入方法依賴的package包/類
public void paintIcon(Component c, Graphics g, int x, int y) {
    Color col = g.getColor();
    try {
        g.setColor(Color.GREEN);
        g.drawRect(x, y, getIconWidth(), getIconHeight());
        g.fillRect(x+3, y+3, getIconWidth()-5, getIconHeight()-5);
    } finally {
        g.setColor(col);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:PropertyMarkingTest.java


注:本文中的java.awt.Graphics.drawRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。