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

The following examples show how to use java.awt.Graphics#drawOval() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/** Properly converts Cartesian coordinates in p into AWT. */
@Override
public void drawElement(Graphics sc, IMultiPoint p) {
	double x = p.getCoordinate(1);  // x
	double y = getHeight() - p.getCoordinate(2);  // y
	
	sc.setColor(Color.white);
	sc.fillOval((int)x-4,(int)y-4,8,8);
	sc.setColor(Color.black);
	sc.drawOval((int)x-4,(int)y-4,8,8);
}
 
Example 2
Source Project: jdk8u-jdk   File: MyCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 3
@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 4
Source Project: DroidUIBuilder   File: AnalogClock.java    License: Apache License 2.0 5 votes vote down vote up
public void paint(Graphics g)
{
	// 绘制背景
	super.paintBackground(g);
	
	Calendar c = Calendar.getInstance();
	c.setTime(new Date());
	int hrs = c.get(Calendar.HOUR);
	int min = c.get(Calendar.MINUTE);
	double hr_a = Math.toRadians(90 - (hrs + min / 60.0) * 30);
	double hr_m = Math.toRadians(90 - min * 6);
	if (face_scale == null)
	{
		g.setColor(Color.white);
		g.fillOval(getX(), getY(), getWidth(), getHeight());
		g.setColor(Color.black);
		g.drawOval(getX(), getY(), getWidth(), getHeight());
		drawAngleLine(g, hr_a, 0.25);
		drawAngleLine(g, hr_m, 0.45);
	}
	else
	{
		g.drawImage(face_scale, getX(), getY(), null);
		g.drawImage(minute_scale, getX() + getWidth() / 2 - offx, getY(),null);
		g.drawImage(hour_scale, getX() + getWidth() / 2 - offx, getY(),null);
	}
}
 
Example 5
Source Project: ThinkJavaCode2   File: Moire.java    License: MIT License 5 votes vote down vote up
public void paint(Graphics g) {
    int i = 90;
    while (i < getWidth()) {
        g.drawOval(0, 0, i, i);
        i = i + 3;
    }
}
 
Example 6
@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 7
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 8
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 9
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 10
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 11
Source Project: jdk8u-jdk   File: MyCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 12
Source Project: jdk8u_jdk   File: MyCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 13
Source Project: Logisim   File: Led.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintGhost(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Bounds bds = painter.getBounds();
	GraphicsUtil.switchToWidth(g, 2);
	g.drawOval(bds.getX() + 1, bds.getY() + 1, bds.getWidth() - 2, bds.getHeight() - 2);
}
 
Example 14
Source Project: Logisim   File: Drawgates.java    License: GNU General Public License v3.0 5 votes vote down vote up
static void paintNot(Graphics g, int x, int y, int width, int height) {
	int[] xp = new int[4];
	int[] yp = new int[4];
	xp[0] = x - 4;
	yp[0] = y;
	xp[1] = x - width;
	yp[1] = y - height / 2;
	xp[2] = x - width;
	yp[2] = y + height / 2;
	xp[3] = x - 4;
	yp[3] = y;
	g.drawPolyline(xp, yp, 4);
	g.drawOval(x - 4, y - 2, 4, 4);
}
 
Example 15
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 16
@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 17
Source Project: jdk8u-jdk   File: MyCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 18
protected void drawOverlay(final Graphics g) {

		final int z = imp.getCurrentSlice() - 1;

		if (z != last_slice) {
			final Integer fittedIndex = indexToValidIndex.get(z);
			if (fittedIndex != null) {
				final int px = fittedPath.getXUnscaled(fittedIndex.intValue());
				final int py = fittedPath.getYUnscaled(fittedIndex.intValue());
				final int pz = fittedPath.getZUnscaled(fittedIndex.intValue());
				tracerPlugin.setSlicesAllPanes(px, py, pz);
				tracerPlugin.setCrosshair(px, py, pz);
				last_slice = z;
			}
		}

		if (valid[z])
			g.setColor(Color.RED);
		else
			g.setColor(Color.MAGENTA);

		SNT.log("radiuses[" + z + "] is: " + radiuses[z]);

		final int x_top_left = screenXD(centre_x_positions[z] - radiuses[z]);
		final int y_top_left = screenYD(centre_y_positions[z] - radiuses[z]);

		g.fillRect(screenXD(centre_x_positions[z]) - 2, screenYD(centre_y_positions[z]) - 2, 5, 5);

		final int diameter = screenXD(centre_x_positions[z] + radiuses[z])
				- screenXD(centre_x_positions[z] - radiuses[z]);

		g.drawOval(x_top_left, y_top_left, diameter, diameter);

		final double proportion = scores[z] / maxScore;
		final int drawToX = (int) (proportion * (imp.getWidth() - 1));
		if (valid[z])
			g.setColor(Color.GREEN);
		else
			g.setColor(Color.RED);
		g.fillRect(screenX(0), screenY(0), screenX(drawToX) - screenX(0), screenY(2) - screenY(0));

		final int modeOvalX = screenXD(imp.getWidth() / 2.0 - modeRadiuses[z]);
		final int modeOvalY = screenYD(imp.getHeight() / 2.0 - modeRadiuses[z]);
		final int modeOvalDiameter = screenXD(imp.getWidth() / 2.0 + modeRadiuses[z]) - modeOvalX;

		g.setColor(Color.YELLOW);
		g.drawOval(modeOvalX, modeOvalY, modeOvalDiameter, modeOvalDiameter);

		// Show the angle between this one and the other two
		// so we can see where the path is "pinched":
		g.setColor(Color.GREEN);
		final double h = (imp.getWidth() * 3) / 8.0;
		final double centreX = imp.getWidth() / 2.0;
		final double centreY = imp.getHeight() / 2.0;
		final double halfAngle = angles[z] / 2;
		final double rightX = centreX + h * Math.sin(halfAngle);
		final double rightY = centreY - h * Math.cos(halfAngle);
		final double leftX = centreX + h * Math.sin(-halfAngle);
		final double leftY = centreX - h * Math.cos(halfAngle);
		g.drawLine(screenXD(centreX), screenYD(centreY), screenXD(rightX), screenYD(rightY));
		g.drawLine(screenXD(centreX), screenYD(centreY), screenXD(leftX), screenYD(leftY));
	}
 
Example 19
/**
 * Draws the rings for the polar plot.
 * @param panel
 * @param g
 *
 * @return double the ring separation used
 */
public double drawRings(double rmax, DrawingPanel panel, Graphics g) {
  double dr = Math.max(this.dr, 1.0e-9);
  if(autospaceRings) {
    int exponent = (int) (Math.log(rmax)/LOG10);
    double decade = Math.pow(10, exponent-1);
    dr = decade;
    while(rmax/dr>5*MAJOR_TIC) { // increase dr if we have more than 25 rings
      dr *= 2;
      if((dr/decade>3.5)&&(dr/decade<4.5)) {
        dr = 5*decade;
        decade *= 10;
      }
    }
  } else {
    int nrings = (int) (rmax/dr);
    while(nrings>10*MAJOR_TIC) {
      dr *= 2;
      nrings = (int) (rmax/dr);
    }
  }
  int xcenter = panel.xToPix(0);
  int ycenter = panel.yToPix(0);
  int xrad = (int) (panel.getXPixPerUnit()*rmax);
  int yrad = (int) (panel.getYPixPerUnit()*rmax);
  if(interiorColor!=null) {
    g.setColor(interiorColor);
    g.fillOval(xcenter-xrad, ycenter-yrad, 2*xrad, 2*yrad);
  }
  int counter = 0;
  for(double r = 0; r<=rmax; r += dr) {
    g.setColor(gridcolor);
    xrad = panel.xToPix(r)-xcenter;
    yrad = ycenter-panel.yToPix(r);
    if(counter%MAJOR_TIC==0) {
      g.setColor(gridcolor.darker());
    }
    g.drawOval(xcenter-xrad, ycenter-yrad, 2*xrad, 2*yrad);
    counter++;
  }
  return dr;
}
 
Example 20
Source Project: JavaExercises   File: Ball.java    License: GNU General Public License v2.0 4 votes vote down vote up
void paint(Graphics g) {
    g.drawOval(x - radius, y - radius, radius * 2, radius * 2);
    g.drawLine(x + (int)getDX(radius - 4), y + (int)getDY(radius - 4),
        x + (int)getDX(radius + 4), y + (int)getDY(radius + 4));
}