Java Code Examples for java.awt.Graphics#fillOval()

The following examples show how to use java.awt.Graphics#fillOval() .
Example 1
Project: javagame   File: MainPanel.java    License: MIT License 6 votes vote down vote up
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // �w�i�����œh��‚Ԃ�
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, WIDTH, HEIGHT);

    // ���S��`��
    g.setColor(Color.YELLOW);
    g.fillOval(320, 240, 2, 2);
    
    // �t�@�C�A�{�[����`��
    for (int i = 0; i < MAX_FIRES; i++) {
        if (fireball[i].isUsed()) {
            fireball[i].draw(g);
        }
    }
}
 
Example 2
Project: LoveHeartView   File: LoveHeart2.java    License: Apache License 2.0 6 votes vote down vote up
public void paint(Graphics g) {
    double x, y, r;          //�������꼰�뾶
    Image image = this.createImage(WIDTH, HEIGHT);
    Graphics pic = image.getGraphics();
    //����ͼ��
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            r = Math.PI / 45 + Math.PI / 45 * i * (1 - Math.sin(Math.PI / 45 * j)) * 18;
            x = r * Math.cos(Math.PI / 45 * j) * Math.sin(Math.PI / 45 * i) + WIDTH / 2;
            y = -r * Math.sin(Math.PI / 45 * j) + HEIGHT / 2;
            pic.setColor(Color.MAGENTA);
            pic.fillOval((int) x, (int) y, 2, 2);
        }
        //����ͼƬ
        g.drawImage(image, 0, 0, this);
    }
}
 
Example 3
Project: Logisim   File: Led.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 4
Project: Logisim   File: SubcircuitPoker.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void paint(InstancePainter painter) {
	if (painter.getDestination() instanceof Canvas && painter.getData() instanceof CircuitState) {
		Bounds bds = painter.getInstance().getBounds();
		int cx = bds.getX() + bds.getWidth() / 2;
		int cy = bds.getY() + bds.getHeight() / 2;

		int tx = cx + 3;
		int ty = cy + 3;
		int[] xp = { tx - 1, cx + 8, cx + 10, tx + 1 };
		int[] yp = { ty + 1, cy + 10, cy + 8, ty - 1 };
		Graphics g = painter.getGraphics();
		if (mouseDown) {
			g.setColor(MAGNIFYING_INTERIOR_DOWN);
		} else {
			g.setColor(MAGNIFYING_INTERIOR);
		}
		g.fillOval(cx - 5, cy - 5, 10, 10);
		g.setColor(Color.BLACK);
		g.drawOval(cx - 5, cy - 5, 10, 10);
		g.fillPolygon(xp, yp, xp.length);
	}
}
 
Example 5
Project: jsyn   File: RotaryController.java    License: Apache License 2.0 5 votes vote down vote up
private void drawArcIndicator(Graphics g, int x, int y, int radius, double angle) {
    final double DEGREES_PER_RADIAN = 180.0 / Math.PI;
    final int minAngleDegrees = (int) (minAngle * DEGREES_PER_RADIAN);
    final int maxAngleDegrees = (int) (maxAngle * DEGREES_PER_RADIAN);

    int zeroAngleDegrees = (int) (fractionToAngle(baseValue) * DEGREES_PER_RADIAN);

    double arrowSize = radius * 0.95;
    int arcX = x - radius;
    int arcY = y - radius;
    int arcAngle = (int) (angle * DEGREES_PER_RADIAN);
    int arrowX = (int) (arrowSize * Math.cos(angle));
    int arrowY = (int) (arrowSize * Math.sin(angle));

    g.setColor(knobColor.darker().darker());
    g.fillArc(arcX, arcY, 2 * radius, 2 * radius, minAngleDegrees, maxAngleDegrees
            - minAngleDegrees);
    g.setColor(Color.ORANGE);
    g.fillArc(arcX, arcY, 2 * radius, 2 * radius, zeroAngleDegrees, arcAngle - zeroAngleDegrees);

    // fill in middle
    int arcWidth = radius / 4;
    int diameter = ((radius - arcWidth) * 2);
    g.setColor(knobColor);
    g.fillOval(arcWidth + x - radius, arcWidth + y - radius, diameter, diameter);

    g.setColor(lineColor);
    g.drawLine(x, y, x + arrowX, y - arrowY);

}
 
Example 6
Project: openjdk-jdk8u   File: MenuItemIconTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected static ImageIcon createIcon() {
    BufferedImage bi = new BufferedImage(IMAGE_WIDTH_AND_HEIGHT,
            IMAGE_WIDTH_AND_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    Graphics g = bi.createGraphics();
    g.setColor(Color.RED);
    g.fillOval(0, 0, IMAGE_WIDTH_AND_HEIGHT, IMAGE_WIDTH_AND_HEIGHT);
    return new ImageIcon(bi);
}
 
Example 7
Project: The-Kraken-Pathfinding   File: CircularObstacle.java    License: MIT License 5 votes vote down vote up
@Override
	public void print(Graphics g, Display f)
	{
//		if(radius <= 0)
//			g.fillOval(f.XtoWindow(position.getX()) - 5, f.YtoWindow(position.getY()) - 5, 10, 10);
//		else
		g.drawOval(f.XtoWindow(position.getX() - radius), f.YtoWindow(position.getY() + radius), f.distanceXtoWindow((radius) * 2), f.distanceYtoWindow((radius) * 2));
		
		Color c = g.getColor();
		Color cTransparent = new Color(c.getRed(), c.getGreen(), c.getBlue(), 30);
		g.setColor(cTransparent);
		
		g.fillOval(f.XtoWindow(position.getX() - radius), f.YtoWindow(position.getY() + radius), f.distanceXtoWindow((radius) * 2), f.distanceYtoWindow((radius) * 2));		
		g.setColor(c);
	}
 
Example 8
Project: Logisim   File: Joystick.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 9
Project: jsyn   File: RotaryController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Override this method if you want to draw your own knob.
 *
 * @param g graphics context
 * @param x position of center of knob
 * @param y position of center of knob
 * @param radius of knob in pixels
 * @param angle in radians. Zero is straight up.
 */
public void drawKnob(Graphics g, int x, int y, int radius, double angle) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int diameter = radius * 2;
    // Draw shaded side.
    g.setColor(knobColor.darker());
    g.fillOval(x - radius + 2, y - radius + 2, diameter, diameter);
    g.setColor(knobColor);
    g.fillOval(x - radius, y - radius, diameter, diameter);

    // Draw line or other indicator of knob position.
    drawIndicator(g, x, y, radius, angle);
}
 
Example 10
Project: TencentKona-8   File: BasicIconFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    if (b.isSelected() == true) {
        g.fillOval(x+1, y+1, getIconWidth(), getIconHeight());
    }
}
 
Example 11
Project: TencentKona-8   File: AltTabCrashTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void paint(Graphics g, Color c) {
    if (c == null) {
        g.setColor(color);
    } else {
        g.setColor(c);
    }
    g.fillOval(x, y, diameter, diameter);
}
 
Example 12
Project: openjdk-jdk8u-backup   File: RenderTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size;
    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.fillOval(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.fillOval(x, y, size, size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 13
Project: AILibs   File: GMeansTest.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates random datapoints and clusters. Then creates a UI to visualize the clusters. Not a Unit test for obvious reasons. 
 * 
 * @param args Nothing to see here
 */
public static void main(String[] args) {
	Random rand = new Random(SEED);
	
	// generate random points
	ArrayList<DoublePoint> data = new ArrayList<>(DATA_POINT_NUMBER);
	for (int i = 0; i < DATA_POINT_NUMBER; i++) {
		data.add(new DoublePoint( new int[] {rand.nextInt(500), rand.nextInt(500)}));
	}
	
	// create Cluster and results
	GMeans<DoublePoint> cluster = new GMeans<>(data);
	List<CentroidCluster<DoublePoint>> result = cluster.cluster();
	
	
	// create Window
	JFrame frame = new JFrame("Simple Result UI");
	
	@SuppressWarnings("serial")
	Canvas c = new Canvas() {
		@Override
		public void paint(Graphics g) {
			// paint points colored by cluster
			for (CentroidCluster<DoublePoint> centroidCluster : result) {
				g.setColor(new Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)));
				for (DoublePoint point : centroidCluster.getPoints()) {
					g.fillOval((int)point.getPoint()[0]-2, (int)point.getPoint()[1]-2, 4, 4);
				}
			}
			
		}
	};
	c.setSize(500, 500);
	
	frame.getContentPane().add(c);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setSize(500, 500);
	frame.setVisible(true);
	
}
 
Example 14
Project: Logisim   File: ProjectExplorer.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 15
Project: Any-Angle-Pathfinding   File: GridPointDrawer.java    License: The Unlicense 5 votes vote down vote up
private void drawPoint(Graphics g, GridPointSet.ColourPoint point) {
    int x = (int)(width*point.x);
    int y = (int)(height*point.y);

    if (outline >= 0) {
        g.setColor(OUTLINE_COLOR);
        g.fillOval(x-halfCircleSize-halfOutline, y-halfCircleSize-halfOutline, circleSize+outline, circleSize+outline);
    }
    g.setColor(point.color);
    g.fillOval(x-halfCircleSize, y-halfCircleSize, circleSize, circleSize);
    g.setColor(Color.BLACK);
}
 
Example 16
Project: osp   File: Circle.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the circle.
 *
 * @param panel
 * @param g
 */
public void draw(DrawingPanel panel, Graphics g) {
  int xpix = panel.xToPix(x)-pixRadius;
  int ypix = panel.yToPix(y)-pixRadius;
  g.setColor(color);
  g.fillOval(xpix, ypix, 2*pixRadius, 2*pixRadius); // draw the circle onto the screen
}
 
Example 17
Project: ThinkJavaCode   File: Mickey.java    License: MIT License 4 votes vote down vote up
public void boxOval(Graphics g, Rectangle bb) {
    g.fillOval(bb.x, bb.y, bb.width, bb.height);
}
 
Example 18
Project: Logisim   File: PlaRomPanel.java    License: GNU General Public License v3.0 4 votes vote down vote up
@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);
	byte inputs = data.getInputs();
	byte outputs = data.getOutputs();
	byte 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 + 10 + 40 * inputs, IMAGE_BORDER + 100 + 40 * and);
	for (byte i = 1; i <= inputs; i++) {
		Color inputColor = data.getInputValue((byte) (i - 1)).getColor();
		Color notColor = data.getInputValue((byte) (i - 1)).not().getColor();
		g.setColor(inputColor);
		// draw input value
		GraphicsUtil.drawCenteredText(g, data.getInputValue((byte) (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 (byte 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((byte) (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 (byte 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((byte) (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((byte) (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 (byte i = 0; i < and; i++) {
		for (byte j = 0; j < inputs * 2; j++) {
			if (data.getInputAndValue(i, j)) {
				g.setColor(Color.WHITE);
				g.fillOval(IMAGE_BORDER + 6 + 20 * j, IMAGE_BORDER + 66 + 40 * i, 8, 8);
				g.setColor(Color.BLACK);
				g.drawOval(IMAGE_BORDER + 6 + 20 * j, IMAGE_BORDER + 66 + 40 * i, 8, 8);
			}
		}
		for (byte k = 0; k < outputs; k++) {
			if (data.getAndOutputValue(i, k)) {
				g.setColor(Color.WHITE);
				g.fillOval(IMAGE_BORDER + 16 + 40 * (inputs + 1) + 40 * k, IMAGE_BORDER + 66 + 40 * i, 8, 8);
				g.setColor(Color.BLACK);
				g.drawOval(IMAGE_BORDER + 16 + 40 * (inputs + 1) + 40 * k, IMAGE_BORDER + 66 + 40 * i, 8, 8);
			}
		}
	}
	if (hover) {
		g.setColor(Value.TRUE_COLOR);
		if (data.columnhovered < inputs * 2)
			g.drawOval(IMAGE_BORDER + 4 + 20 * data.columnhovered, IMAGE_BORDER + 64 + 40 * data.rowhovered, 12,
					12);
		else
			g.drawOval(IMAGE_BORDER + 14 + 40 * (inputs + 1) + 40 * (data.columnhovered - 2 * inputs),
					IMAGE_BORDER + 64 + 40 * data.rowhovered, 12, 12);
	}
}
 
Example 19
Project: JavaExercises   File: Ball.java    License: GNU General Public License v2.0 4 votes vote down vote up
void paint(Graphics g) {
    g.setColor(color);
    g.fillOval(x, y, d, d);
    g.setColor(Color.black);
    g.drawOval(x, y, d, d);
}
 
Example 20
Project: RipplePower   File: GraphicsUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 以指定位置、指定大小绘制指定椭圆形
 * 
 * @param g
 * @param x
 * @param y
 * @param width
 * @param height
 * @param color
 */
public static void rectOval(Graphics g, int x, int y, int width, int height, Color color) {
	g.setColor(color);
	g.drawOval(x, y, width, height);
	g.fillOval(x, y, width, height);
}