Java Code Examples for java.awt.Graphics.drawRect()

The following are Jave code examples for showing how to use drawRect() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jmt   File: KFuzzyScatter.java   View Source Code Vote up 6 votes
@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);
		}
	}
}
 
Example 2
Project: openjdk-jdk10   File: MetalBorders.java   View Source Code Vote up 6 votes
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 );

}
 
Example 3
Project: powertext   File: ErrorStrip.java   View Source Code Vote up 6 votes
@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);

}
 
Example 4
Project: JDigitalSimulator   File: ALU74181.java   View Source Code Vote up 6 votes
@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);
}
 
Example 5
Project: openjdk-jdk10   File: MultiResolutionDrawImageWithTransformTest.java   View Source Code Vote up 6 votes
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);
}
 
Example 6
Project: incubator-netbeans   File: TableSheetCell.java   View Source Code Vote up 6 votes
@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);
    }
}
 
Example 7
Project: VASSAL-src   File: ColorButton.java   View Source Code Vote up 6 votes
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);
  }
}
 
Example 8
Project: jdk8u-jdk   File: MotifGraphicsUtils.java   View Source Code Vote up 6 votes
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);
}
 
Example 9
Project: New-Kepard   File: JWindow.java   View Source Code Vote up 5 votes
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);	
}
 
Example 10
Project: anti-fanmei   File: FunPlot.java   View Source Code Vote up 5 votes
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;
	
	}
}
 
Example 11
Project: rapidminer   File: ItemPanel.java   View Source Code Vote up 5 votes
@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();

		}
	}
}
 
Example 12
Project: Logisim   File: CounterPoker.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 13
Project: jmt   File: SmallCDF.java   View Source Code Vote up 5 votes
@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);

}
 
Example 14
Project: scorekeeperfrontend   File: CarDialog.java   View Source Code Vote up 5 votes
@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);
}
 
Example 15
Project: incubator-netbeans   File: PropertyMarkingTest.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 16
Project: JDigitalSimulator   File: HalfAdder.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics graphics) {
	graphics.setColor(Color.BLACK);
	graphics.setFont(graphics.getFont().deriveFont(8f));
	int top = size.height/4, height=graphics.getFontMetrics().getAscent()/2;
	graphics.drawRect(5, 0, size.width-10, size.height);
	graphics.drawString("A", 10, top+height);
	graphics.drawString("B", 10, top*3+height);
	graphics.drawString("S", size.width-15, top+height);
	graphics.drawString("C", size.width-15, top*3+height);
	graphics.setFont(graphics.getFont().deriveFont(Font.BOLD, 15f));
	FontMetrics metrics = graphics.getFontMetrics();
	graphics.drawString("HA", size.width/2-metrics.stringWidth("HA")/2,
			size.height/2+metrics.getAscent()/3);
	ContactUtilities.paintSolderingJoints(graphics, contacts);
}
 
Example 17
Project: incubator-netbeans   File: DefaultTabbedContainerUI.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y, int w,
                        int h) {
    g.translate(x, y);

    g.setColor(UIManager.getColor("controlShadow")); //NOI18N
    g.drawRect(0, 0, w - 2, h - 2);
    g.setColor(UIManager.getColor("controlHighlight")); //NOI18N
    g.drawLine(w - 1, 1, w - 1, h - 1);
    g.drawLine(1, h - 1, w - 1, h - 1);

    g.translate(-x, -y);
}
 
Example 18
Project: openjdk-jdk10   File: MotifBorders.java   View Source Code Vote up 4 votes
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    boolean isPressed = false;
    boolean hasFocus = false;
    boolean canBeDefault = false;
    boolean isDefault = false;

    if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton)c;
        ButtonModel model = b.getModel();

        isPressed = (model.isArmed() && model.isPressed());
        hasFocus = (model.isArmed() && isPressed) ||
                   (b.isFocusPainted() && b.hasFocus());
        if (b instanceof JButton) {
            canBeDefault = ((JButton)b).isDefaultCapable();
            isDefault = ((JButton)b).isDefaultButton();
        }
    }
    int bx1 = x+1;
    int by1 = y+1;
    int bx2 = x+w-2;
    int by2 = y+h-2;

    if (canBeDefault) {
        if (isDefault) {
            g.setColor(shadow);
            g.drawLine(x+3, y+3, x+3, y+h-4);
            g.drawLine(x+3, y+3, x+w-4, y+3);

            g.setColor(highlight);
            g.drawLine(x+4, y+h-4, x+w-4, y+h-4);
            g.drawLine(x+w-4, y+3, x+w-4, y+h-4);
        }
        bx1 +=6;
        by1 += 6;
        bx2 -= 6;
        by2 -= 6;
    }

    if (hasFocus) {
        g.setColor(focus);
        if (isDefault) {
            g.drawRect(x, y, w-1, h-1);
        } else {
            g.drawRect(bx1-1, by1-1, bx2-bx1+2, by2-by1+2);
        }
    }

    g.setColor(isPressed? shadow : highlight);
    g.drawLine(bx1, by1, bx2, by1);
    g.drawLine(bx1, by1, bx1, by2);

    g.setColor(isPressed? highlight : shadow);
    g.drawLine(bx2, by1+1, bx2, by2);
    g.drawLine(bx1+1, by2, bx2, by2);
}
 
Example 19
Project: OpenJSharp   File: MotifBorders.java   View Source Code Vote up 4 votes
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    boolean isPressed = false;
    boolean hasFocus = false;
    boolean canBeDefault = false;
    boolean isDefault = false;

    if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton)c;
        ButtonModel model = b.getModel();

        isPressed = (model.isArmed() && model.isPressed());
        hasFocus = (model.isArmed() && isPressed) ||
                   (b.isFocusPainted() && b.hasFocus());
        if (b instanceof JButton) {
            canBeDefault = ((JButton)b).isDefaultCapable();
            isDefault = ((JButton)b).isDefaultButton();
        }
    }
    int bx1 = x+1;
    int by1 = y+1;
    int bx2 = x+w-2;
    int by2 = y+h-2;

    if (canBeDefault) {
        if (isDefault) {
            g.setColor(shadow);
            g.drawLine(x+3, y+3, x+3, y+h-4);
            g.drawLine(x+3, y+3, x+w-4, y+3);

            g.setColor(highlight);
            g.drawLine(x+4, y+h-4, x+w-4, y+h-4);
            g.drawLine(x+w-4, y+3, x+w-4, y+h-4);
        }
        bx1 +=6;
        by1 += 6;
        bx2 -= 6;
        by2 -= 6;
    }

    if (hasFocus) {
        g.setColor(focus);
        if (isDefault) {
            g.drawRect(x, y, w-1, h-1);
        } else {
            g.drawRect(bx1-1, by1-1, bx2-bx1+2, by2-by1+2);
        }
    }

    g.setColor(isPressed? shadow : highlight);
    g.drawLine(bx1, by1, bx2, by1);
    g.drawLine(bx1, by1, bx1, by2);

    g.setColor(isPressed? highlight : shadow);
    g.drawLine(bx2, by1+1, bx2, by2);
    g.drawLine(bx1+1, by2, bx2, by2);
}
 
Example 20
Project: JDigitalSimulator   File: ExamplePluginFull.java   View Source Code Vote up 3 votes
/**
 * Let us implement our first method. So we will have to
 *    <code>@Override public void paint(Graphics graphics)</code> //XXX
 * of the <code>Paintable</code> interface.
 * This method is used to draw the whole component and is called for the first time when
 * generating a preview image for the component-catalog of the JDigitalSimulator.
 * You may use every possibility to paint your component provided by the java
 * <code>Graphics2D</code> classes, as described in the java documentation.
 * It is strictly recommended that you only draw into the bounds of your own Component! It is
 * a known-feature that you are able to draw outside of your component bounds (returned by
 * <code>getSize</code>, but do not do it if you do not know exactly what you are doing.
 * Note: Do <bold>not</bold> use this method for calculating anything! This method will be
 *       likely get called when something changes on the frontend, but it is not guaranteed in
 *       any ways, that it: a) is called every time b) called in fixed time intervals.
 * Please use the calculate method for this reason, described later on.
 */
@Override public void paint(Graphics graphics) {
	Dimension size = getSize(); /** you may call other (even private) methods in here! */
	graphics.setColor(Color.BLACK); /** do not assume the color does fit right away */
	graphics.drawRect(0, 0, size.width, size.height); /** only draw inside this bounds! */
	graphics.drawString(getAttributes().name, 0, 30);
	/** there is no need to call the super.paint method for any reason */
}