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

The following are Jave code examples for showing how to use drawOval() 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: Logisim   File: Led.java   View Source Code Vote up 7 votes
@Override
public void paintInstance(InstancePainter painter) {
	InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
	Value val = data == null ? Value.FALSE : (Value) data.getValue();
	Bounds bds = painter.getBounds().expand(-1);

	Graphics g = painter.getGraphics();
	if (painter.getShowState()) {
		Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
		Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
		Boolean activ = painter.getAttributeValue(Io.ATTR_ACTIVE);
		Object desired = activ.booleanValue() ? Value.TRUE : Value.FALSE;
		g.setColor(val == desired ? onColor : offColor);
		g.fillOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
	}
	g.setColor(Color.BLACK);
	GraphicsUtil.switchToWidth(g, 2);
	g.drawOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
	GraphicsUtil.switchToWidth(g, 1);
	painter.drawLabel();
	painter.drawPorts();
}
 
Example 2
Project: Logisim   File: Buzzer.java   View Source Code Vote up 7 votes
@Override
public void paintInstance(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Bounds b = painter.getBounds();

	int x = b.getX();
	int y = b.getY();

	g.setColor(Color.BLACK);

	for (int k = 0; k <= 20; k += 5)
		g.drawOval((x + 20) - k, (y + 20) - k, k * 2, k * 2);

	painter.drawPort(0);
	painter.drawPort(1);
	painter.drawPort(2);

	Data d = (Data) painter.getData();
	if (d != null && d.is_on) {
		d.still_alive = true;
		if (!d.thread.isAlive())
			d.StartThread();
	}
}
 
Example 3
Project: Logisim   File: SimulationTreeRenderer.java   View Source Code Vote up 6 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, g);
	factory.paintIcon(context, x, y, factory.createAttributeSet());

	// draw magnifying glass if appropriate
	if (isCurrentView) {
		int tx = x + 13;
		int ty = y + 13;
		int[] xp = { tx - 1, x + 18, x + 20, tx + 1 };
		int[] yp = { ty + 1, y + 20, y + 18, ty - 1 };
		g.setColor(ProjectExplorer.MAGNIFYING_INTERIOR);
		g.fillOval(x + 5, y + 5, 10, 10);
		g.setColor(Color.BLACK);
		g.drawOval(x + 5, y + 5, 10, 10);
		g.fillPolygon(xp, yp, xp.length);
	}
}
 
Example 4
Project: LivroJavaComoProgramar10Edicao   File: LinesRectsOvalsJPanel.java   View Source Code Vote up 6 votes
@Override
public void paintComponent(Graphics g)
{
   super.paintComponent(g); 
   this.setBackground(Color.WHITE);

   g.setColor(Color.RED);
   g.drawLine(5, 30, 380, 30);

   g.setColor(Color.BLUE);
   g.drawRect(5, 40, 90, 55);
   g.fillRect(100, 40, 90, 55);

   g.setColor(Color.BLACK);
   g.fillRoundRect(195, 40, 90, 55, 50, 50);
   g.drawRoundRect(290, 40, 90, 55, 20, 20);

   g.setColor(Color.GREEN);   
   g.draw3DRect(5, 100, 90, 55, true);
   g.fill3DRect(100, 100, 90, 55, false);

   g.setColor(Color.MAGENTA);
   g.drawOval(195, 100, 90, 55);
   g.fillOval(290, 100, 90, 55);
}
 
Example 5
Project: Logisim   File: ControlledBuffer.java   View Source Code Vote up 6 votes
@Override
public void paintIcon(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Icon icon = isInverter ? ICON_INVERTER : ICON_BUFFER;
	if (icon != null) {
		icon.paintIcon(painter.getDestination(), g, 2, 2);
	} else {
		int x = isInverter ? 0 : 2;
		g.setColor(Color.BLACK);
		int[] xp = new int[] { x + 15, x + 1, x + 1, x + 15 };
		int[] yp = new int[] { 10, 3, 17, 10 };
		g.drawPolyline(xp, yp, 4);
		if (isInverter)
			g.drawOval(x + 13, 8, 4, 4);
		g.setColor(Value.FALSE_COLOR);
		g.drawLine(x + 8, 14, x + 8, 18);
	}
}
 
Example 6
Project: Logisim   File: AppearanceAnchor.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g, HandleGesture gesture) {
	Location location = getLocation();
	int x = location.getX();
	int y = location.getY();
	g.setColor(SYMBOL_COLOR);
	g.drawOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
	Location e0 = location.translate(facing, RADIUS);
	Location e1 = location.translate(facing, RADIUS + INDICATOR_LENGTH);
	g.drawLine(e0.getX(), e0.getY(), e1.getX(), e1.getY());
}
 
Example 7
Project: jdk8u-jdk   File: MyCursor.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics gr) {
    gr.setColor(Color.GREEN);
    ((Graphics2D)gr).setStroke(new BasicStroke(3));

    gr.translate(width/2, height/2);
    int R = width/4;
    gr.drawOval(-R, -R, 2*R, 2*R);
    gr.drawLine(-R, R, R, -R);
}
 
Example 8
Project: openjdk-jdk10   File: MyCursor.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics gr) {
    gr.setColor(Color.GREEN);
    ((Graphics2D)gr).setStroke(new BasicStroke(3));

    gr.translate(width/2, height/2);
    int R = width/4;
    gr.drawOval(-R, -R, 2*R, 2*R);
    gr.drawLine(-R, R, R, -R);
}
 
Example 9
Project: Logisim   File: XnorGate.java   View Source Code Vote up 5 votes
@Override
public void paintIconShaped(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	GraphicsUtil.drawCenteredArc(g, 0, -5, 22, -90, 53);
	GraphicsUtil.drawCenteredArc(g, 0, 23, 22, 90, -53);
	GraphicsUtil.drawCenteredArc(g, -8, 9, 16, -30, 60);
	GraphicsUtil.drawCenteredArc(g, -10, 9, 16, -30, 60);
	g.drawOval(16, 8, 4, 4);
}
 
Example 10
Project: Logisim   File: AbstractGate.java   View Source Code Vote up 5 votes
protected void paintIconRectangular(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	g.drawRect(1, 2, 16, 16);
	if (negateOutput)
		g.drawOval(16, 8, 4, 4);
	String label = getRectangularLabel(painter.getAttributeSet());
	GraphicsUtil.drawCenteredText(g, label, 9, 8);
}
 
Example 11
Project: Logisim   File: NotGate.java   View Source Code Vote up 5 votes
@Override
public void paintIcon(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	g.setColor(Color.black);
	if (painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) {
		if (toolIconRect != null) {
			toolIconRect.paintIcon(painter.getDestination(), g, 2, 2);
		} else {
			g.drawRect(0, 2, 16, 16);
			GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
			g.drawOval(16, 8, 4, 4);
		}
	} else if (painter.getGateShape() == AppPreferences.SHAPE_DIN40700) {
		if (toolIconDin != null) {
			toolIconDin.paintIcon(painter.getDestination(), g, 2, 2);
		} else {
			g.drawRect(0, 2, 16, 16);
			GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
			g.drawOval(16, 8, 4, 4);
		}
	} else {
		if (toolIcon != null) {
			toolIcon.paintIcon(painter.getDestination(), g, 2, 2);
		} else {
			int[] xp = new int[4];
			int[] yp = new int[4];
			xp[0] = 15;
			yp[0] = 10;
			xp[1] = 1;
			yp[1] = 3;
			xp[2] = 1;
			yp[2] = 17;
			xp[3] = 15;
			yp[3] = 10;
			g.drawPolyline(xp, yp, 4);
			g.drawOval(15, 8, 4, 4);
		}
	}
}
 
Example 12
Project: LivroJavaComoProgramar10Edicao   File: MyOval.java   View Source Code Vote up 5 votes
public void draw(Graphics g)
{
   g.setColor(getColor());
   
   if (isFilled())
      g.fillOval(getUpperLeftX(), getUpperLeftY(),
         getWidth(), getHeight());
   else
      g.drawOval(getUpperLeftX(), getUpperLeftY(),
         getWidth(), getHeight());
}
 
Example 13
Project: Logisim   File: ProjectExplorer.java   View Source Code Vote up 5 votes
@Override
public void paintIcon(java.awt.Component c, Graphics g, int x, int y) {
	// draw halo if appropriate
	if (tool == haloedTool && AppPreferences.ATTRIBUTE_HALO.getBoolean()) {
		g.setColor(Canvas.HALO_COLOR);
		g.fillRoundRect(x, y, getIconWidth(), getIconHeight(), 5, 5);
		g.setColor(Color.BLACK);
	}

	// draw tool icon
	Graphics gIcon = g.create();
	ComponentDrawContext context = new ComponentDrawContext(ProjectExplorer.this, null, null, g, gIcon);
	tool.paintIcon(context, x, y);
	gIcon.dispose();

	// draw magnifying glass if appropriate
	if (circ == proj.getCurrentCircuit()) {
		int tx = x + 13;
		int ty = y + 13;
		int[] xp = { tx - 1, x + 18, x + 20, tx + 1 };
		int[] yp = { ty + 1, y + 20, y + 18, ty - 1 };
		g.setColor(MAGNIFYING_INTERIOR);
		g.fillOval(x + 5, y + 5, 10, 10);
		g.setColor(Color.darkGray);
		g.drawOval(x + 5, y + 5, 10, 10);
		g.fillPolygon(xp, yp, xp.length);
	}
}
 
Example 14
Project: Logisim   File: Joystick.java   View Source Code Vote up 5 votes
private static void drawBall(Graphics g, int x, int y, Color c, boolean inColor) {
	if (inColor) {
		g.setColor(c == null ? Color.RED : c);
	} else {
		int hue = c == null ? 128 : (c.getRed() + c.getGreen() + c.getBlue()) / 3;
		g.setColor(new Color(hue, hue, hue));
	}
	GraphicsUtil.switchToWidth(g, 1);
	g.fillOval(x - 4, y - 4, 8, 8);
	g.setColor(Color.BLACK);
	g.drawOval(x - 4, y - 4, 8, 8);
}
 
Example 15
Project: Logisim   File: Buzzer.java   View Source Code Vote up 5 votes
@Override
public void paintGhost(InstancePainter painter) {
	Bounds b = painter.getBounds();
	Graphics g = painter.getGraphics();
	g.setColor(Color.GRAY);
	g.drawOval(b.getX(), b.getY(), 40, 40);
}
 
Example 16
Project: candlelight   File: MatterRenderer.java   View Source Code Vote up 5 votes
public void draw(Graphics g, Matter matter)
{
	int centerX = (int) matter.posX;
	int centerY = (int) matter.posY;
	int radius = (int) matter.radius;
	int size = radius * 2;
	float dir = matter.rotation;

	int bodyFromX = centerX - radius;
	int bodyFromY = centerY - radius;

	g.setColor(matter.getColor());
	g.fillOval(bodyFromX, bodyFromY, size, size);

	g.setColor(COLOR_OUTLINE);
	g.drawOval(bodyFromX, bodyFromY, size, size);
	g.drawLine(centerX, centerY,
			centerX + (int) (Math.cos(dir) * radius),
			centerY + (int) (Math.sin(dir) * radius));

	if (matter instanceof Pye)
	{
		Pye pye = (Pye) matter;
		for(Appendage appendage : pye.getAppendages())
		{
			if (appendage == null) continue;
			int i = pye.indexOf(appendage);
			Vector2f vec = pye.getPosition(i, new Vector2f());
			g.setColor(Color.GREEN);
			g.fillOval((int) vec.x() - 2, (int) vec.y() - 2, 4, 4);
		}
	}
}
 
Example 17
Project: OpenJSharp   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    if (rctx.animate) {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawOval(x, y, size, size);
            if ((x -= 3) < 0) x += rctx.maxX;
            if ((y -= 1) < 0) y += rctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawOval(x, y, size, size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 18
Project: Logisim   File: PlaRomPanel.java   View Source Code Vote up 4 votes
@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);
	}
	super.paintComponent(g);
	int inputs = data.getInputs();
	int outputs = data.getOutputs();
	int and = data.getAnd();
	GraphicsUtil.switchToWidth(g, 2);
	g.setColor(Color.DARK_GRAY);
	g.setFont(new Font("sans serif", Font.BOLD, 14));
	GraphicsUtil.drawCenteredText(g, "\u2190" + Strings.getter("demultiplexerInTip").toString(),
			40 * (inputs + 1) - (20 - IMAGE_BORDER) + 5, IMAGE_BORDER);
	GraphicsUtil.drawCenteredText(g, Strings.getter("multiplexerOutTip").toString() + "\u2192",
			IMAGE_BORDER + 20 + 40 * inputs - 10, IMAGE_BORDER + 100 + 40 * and);
	for (Integer i = 1; i <= inputs; i++) {
		Color inputColor = data.getInputValue(i - 1).getColor();
		Color notColor = data.getInputValue(i - 1).not().getColor();
		g.setColor(inputColor);
		// draw input value
		GraphicsUtil.drawCenteredText(g, data.getInputValue(i - 1).toString(), 40 * i - (20 - IMAGE_BORDER),
				IMAGE_BORDER);
		g.drawLine(40 * i - (20 - IMAGE_BORDER), IMAGE_BORDER + 15, 40 * i - (20 - IMAGE_BORDER),
				IMAGE_BORDER + 22);
		g.drawLine(40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 22, 40 * i - (10 - IMAGE_BORDER),
				IMAGE_BORDER + 22);
		g.drawLine(40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 22, 40 * i - (30 - IMAGE_BORDER),
				IMAGE_BORDER + 30);
		g.drawLine(40 * i - (10 - IMAGE_BORDER), IMAGE_BORDER + 22, 40 * i - (10 - IMAGE_BORDER),
				IMAGE_BORDER + 70 + 40 * (and - 1));
		g.setColor(notColor);
		g.drawLine(40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 50, 40 * i - (30 - IMAGE_BORDER),
				IMAGE_BORDER + 70 + 40 * (and - 1));
		g.setColor(Color.BLACK);
		drawNot(g, 40 * i - (30 - IMAGE_BORDER), IMAGE_BORDER + 30);
	}
	for (Integer i = 1; i <= and; i++) {
		g.drawLine(IMAGE_BORDER + 10, IMAGE_BORDER + 30 + 40 * i, IMAGE_BORDER + 4 + 40 * inputs,
				IMAGE_BORDER + 30 + 40 * i);
		g.setColor(data.getAndValue(i - 1).getColor());
		g.drawLine(IMAGE_BORDER + 36 + 40 * inputs, IMAGE_BORDER + 30 + 40 * i,
				IMAGE_BORDER + 40 * (inputs + 1) + 20 + 40 * (outputs - 1), IMAGE_BORDER + 30 + 40 * i);
		g.setColor(Color.BLACK);
		Drawgates.paintAnd(g, IMAGE_BORDER + 36 + 40 * inputs, IMAGE_BORDER + 30 + 40 * i, 32, 32, false);
	}
	for (Integer i = 1; i <= outputs; i++) {
		g.drawLine(IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 70, IMAGE_BORDER + 20 + 40 * (inputs + i),
				IMAGE_BORDER + 54 + 40 * and);
		g.setColor(data.getOutputValue(i - 1).getColor());
		g.drawLine(IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 82 + 40 * and,
				IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 89 + 40 * and);
		GraphicsUtil.drawCenteredText(g, data.getOutputValue(i - 1).toString(),
				IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 100 + 40 * and);
		g.setColor(Color.BLACK);
		drawOr(g, IMAGE_BORDER + 20 + 40 * (inputs + i), IMAGE_BORDER + 54 + 40 * and);
	}
	for (int i = 0; i < and; i++) {
		for (int j = 0; j < inputs * 2; j++) {
			if (data.getInputAndValue(i, j)) {
				g.setColor(Color.WHITE);
				g.fillOval(IMAGE_BORDER + 10 + 20 * j - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8, 8);
				g.setColor(Color.BLACK);
				g.drawOval(IMAGE_BORDER + 10 + 20 * j - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8, 8);
			}
		}
		for (int k = 0; k < outputs; k++) {
			if (data.getAndOutputValue(i, k)) {
				g.setColor(Color.WHITE);
				g.fillOval(IMAGE_BORDER + 20 + 40 * (inputs + 1) + 40 * k - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8,
						8);
				g.setColor(Color.BLACK);
				g.drawOval(IMAGE_BORDER + 20 + 40 * (inputs + 1) + 40 * k - 4, IMAGE_BORDER + 70 + 40 * i - 4, 8,
						8);
			}
		}
	}
}
 
Example 19
Project: Logisim   File: Pin.java   View Source Code Vote up 4 votes
private void paintIconBase(InstancePainter painter, BitWidth w) {
	PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
	Direction dir = attrs.facing;
	boolean output = attrs.isOutput();
	boolean iconprinted = false;
	Graphics g = painter.getGraphics();
	g.setFont(ICON_WIDTH_FONT);
	if (output) {
		if (w.equals(BitWidth.ONE) && ICON_OUT != null) {
			Icons.paintRotated(g, 2, 2, dir, ICON_OUT, painter.getDestination());
			iconprinted = true;
		} else if (ICON_OUT_MULTI != null) {
			Icons.paintRotated(g, 2, 2, dir, ICON_OUT_MULTI, painter.getDestination());
			iconprinted = true;
		}
	} else {
		if (w.equals(BitWidth.ONE) && ICON_IN != null) {
			Icons.paintRotated(g, 2, 2, dir, ICON_IN, painter.getDestination());
			iconprinted = true;
		} else if (ICON_IN_MULTI != null) {
			Icons.paintRotated(g, 2, 2, dir, ICON_IN_MULTI, painter.getDestination());
			iconprinted = true;
		}
	}
	if (!iconprinted) {
		int pinx = 16;
		int piny = 9;
		if (dir == Direction.EAST) { // keep defaults
		} else if (dir == Direction.WEST) {
			pinx = 4;
		} else if (dir == Direction.NORTH) {
			pinx = 9;
			piny = 4;
		} else if (dir == Direction.SOUTH) {
			pinx = 9;
			piny = 16;
		}
		g.setColor(w.equals(BitWidth.ONE) ? Value.TRUE.getColor() : Color.WHITE);
		if (output) {
			g.fillOval(4, 4, 13, 13);
		} else {
			g.fillRect(4, 4, 13, 13);
		}
		g.fillOval(pinx, piny, 3, 3);

		g.setColor(Color.black);
		if (output) {
			g.drawOval(4, 4, 13, 13);
		} else {
			g.drawRect(4, 4, 13, 13);
		}
	}
	if (w.equals(BitWidth.ONE))
		g.setColor(Color.WHITE);
	else
		g.setColor(Color.BLACK);
	GraphicsUtil.drawCenteredText(g, "" + w.getWidth(), 10, 9);
}
 
Example 20
Project: Logisim   File: Pin.java   View Source Code Vote up 4 votes
@Override
public void paintInstance(InstancePainter painter) {
	PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
	Graphics g = painter.getGraphics();
	// intentionally with no graphics object - we don't want label included
	Bounds bds = painter.getInstance().getBounds();
	int x = bds.getX();
	int y = bds.getY();
	GraphicsUtil.switchToWidth(g, 2);
	g.setColor(painter.getAttributeValue(StdAttr.ATTR_LABEL_COLOR));
	painter.drawLabel();
	// if bitwidth is more that 1, first draw the bounds and then the number
	if (attrs.width.getWidth() > 1) {
		g.setColor(Color.black);
		if (attrs.type == EndData.OUTPUT_ONLY) {
			painter.drawRoundBounds(Color.WHITE);
		} else {
			painter.drawBounds(Color.WHITE);
		}
	}

	if (!painter.getShowState()) {
		g.setColor(Color.BLACK);
		GraphicsUtil.drawCenteredText(g, "x" + attrs.width.getWidth(), bds.getX() + bds.getWidth() / 2,
				bds.getY() + bds.getHeight() / 2);
	} else {
		PinState state = getState(painter);
		if (attrs.width.getWidth() <= 1) {
			Value receiving = state.receiving;
			g.setColor(receiving.getColor());
			if (attrs.type == EndData.OUTPUT_ONLY)
				g.fillOval(x, y, bds.getWidth(), bds.getHeight());
			else
				g.fillRect(x, y, bds.getWidth(), bds.getHeight());
			if (attrs.width.getWidth() == 1) {
				g.setColor(Color.WHITE);
				GraphicsUtil.drawCenteredText(g, state.sending.toDisplayString(), x + 11, y + 8);
			}
		} else {
			Probe.paintValue(painter, state.sending);
		}
	}
	// if bitwidth is equal to 1, first draw the colored base and value, then the
	// bounds
	if (attrs.width.getWidth() == 1) {
		g.setColor(Color.black);
		if (attrs.type == EndData.OUTPUT_ONLY) {
			g.drawOval(x, y, bds.getWidth(), bds.getHeight());
		} else {
			g.drawRect(x, y, bds.getWidth(), bds.getHeight());
		}
	}
	painter.drawPorts();
}