下面列出了java.awt.Graphics2D#fillOval ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2d = (Graphics2D) g;
//Render settings
//g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//Border
g2d.setColor(Color.BLACK);
g2d.fillOval(x + 2, y + 2, getIconWidth() - 4, getIconHeight() - 4);
//Background
g2d.setColor(color);
g2d.fillOval(x + 3, y + 3, getIconWidth() - 6, getIconHeight() - 6);
}
@Override
public void paintIcon(Component c, Graphics g1, int x, int y) {
Graphics2D g = (Graphics2D) g1;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
Stroke oldStroke = g.getStroke();
g.setColor(hover ? Color.GRAY : Color.LIGHT_GRAY);
g.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.fillOval(x + 2, y + 2, 18, 18);
g.setColor(Color.WHITE);
g.drawLine(x + 6, y + 6, x + 15, y + 15);
g.drawLine(x + 15, y + 6, x + 6, y + 15);
g.setStroke(oldStroke);
}
private static void render(Graphics g, int w, int h, boolean useNonOpaque) {
if (useNonOpaque) {
Graphics2D g2d = (Graphics2D)g;
GradientPaint p =
new GradientPaint(0.0f, 0.0f,
new Color(rnd.nextInt(0xffffff)),
w, h,
new Color(rnd.nextInt(0xff),
rnd.nextInt(0xff),
rnd.nextInt(0xff), 0),
true);
g2d.setPaint(p);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.fillOval(0, 0, w, h);
} else {
g.setColor(new Color(rnd.nextInt(0xffffff)));
g.fillRect(0, 0, w, h);
}
}
@Override
public Dimension render(Graphics2D g)
{
g.setColor(color);
final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
final Point mousePosition = new Point(mouseCanvasPosition.getX() - RADIUS, mouseCanvasPosition.getY() - RADIUS);
final Rectangle bounds = new Rectangle(mousePosition.x, mousePosition.y, 2 * RADIUS, 2 * RADIUS);
g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
return bounds.getSize();
}
public void paint(Graphics g) {
if (selectedValues.isEmpty()) return;
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHints(chart.getRenderingHints());
Iterator<Point> it = selectedValues.iterator();
boolean linePainted = false;
while (it.hasNext()) {
Point p = it.next();
if (!linePainted) {
g2.setPaint(evenPerfPaint);
g2.setStroke(evenPerfStroke);
g2.drawLine(p.x, 0, p.x, getHeight());
g2.setPaint(oddPerfPaint);
g2.setStroke(oddPerfStroke);
g2.drawLine(p.x, 0, p.x, getHeight());
g2.setPaint(markPaint);
g2.setStroke(markStroke);
linePainted = true;
}
g2.fillOval(p.x - selectionExtent + 1, p.y - selectionExtent + 1,
selectionExtent * 2 - 1, selectionExtent * 2 - 1);
}
}
private static Image createTrayIconImage() {
/**
* Create a small image of a red circle to use as the icon for the tray icon
*/
int trayIconImageSize = 32;
final BufferedImage trayImage = new BufferedImage(trayIconImageSize, trayIconImageSize, BufferedImage.TYPE_INT_ARGB);
final Graphics2D trayImageGraphics = (Graphics2D) trayImage.getGraphics();
trayImageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
trayImageGraphics.setColor(new Color(255, 255, 255, 0));
trayImageGraphics.fillRect(0, 0, trayImage.getWidth(), trayImage.getHeight());
trayImageGraphics.setColor(Color.red);
int trayIconImageInset = 4;
trayImageGraphics.fillOval(trayIconImageInset,
trayIconImageInset,
trayImage.getWidth() - 2 * trayIconImageInset,
trayImage.getHeight() - 2 * trayIconImageInset);
trayImageGraphics.setColor(Color.darkGray);
trayImageGraphics.drawOval(trayIconImageInset,
trayIconImageInset,
trayImage.getWidth() - 2 * trayIconImageInset,
trayImage.getHeight() - 2 * trayIconImageInset);
return trayImage;
}
private static BufferedImage createTestImage(int type) throws IOException {
int w = 200;
int h = 200;
BufferedImage b = new BufferedImage(w, h, type);
Graphics2D g = b.createGraphics();
g.setColor(Color.white);
g.fillRect(0,0, w, h);
g.setColor(Color.black);
g.fillOval(10, 10, w -20, h-20);
return b;
}
@Override
public void drawOverlays( final Graphics g )
{
final Graphics2D graphics = ( Graphics2D ) g;
final int t = viewer.getState().getCurrentTimepoint();
final double[] lPos = new double[ 3 ];
final double[] gPos = new double[ 3 ];
final AffineTransform3D transform = new AffineTransform3D();
for ( final InterestPointSource pointSource : interestPointSources )
{
pointSource.getLocalToGlobalTransform( t, transform );
transform.preConcatenate( viewerTransform );
for ( final RealLocalizable p : pointSource.getLocalCoordinates( t ) )
{
p.localize( lPos );
transform.apply( lPos, gPos );
final double size = getPointSize( gPos );
final int x = ( int ) ( gPos[ 0 ] - 0.5 * size );
final int y = ( int ) ( gPos[ 1 ] - 0.5 * size );
final int w = ( int ) size;
graphics.setColor( getColor( gPos ) );
graphics.fillOval( x, y, w, w );
}
}
}
private static BufferedImage createTestImage(int type)
throws IOException {
int w = 200;
int h = 200;
BufferedImage b = new BufferedImage(w, h, type);
Graphics2D g = b.createGraphics();
g.setColor(Color.white);
g.fillRect(0,0, w, h);
g.setColor(Color.black);
g.fillOval(10, 10, w -20, h-20);
return b;
}
@Override
protected void paint(Component c, Graphics2D g, int x, int y) {
g.fillOval(x + 1, y + 1, 5, 5);
g.fillOval(x + 2, y + 4, 5, 5);
g.fillOval(x + 5, y + 7, 5, 5);
g.fillOval(x + 3, y + 2, 5, 5);
g.fillOval(x + 10, y + 7, 5, 5);
}
private void paintBar(Graphics2D g) {
List<String> list = getPaintingModel().getPositions();
int barStartY = getBarStartY();
g.setColor(BAR_COLOR);
g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);
int circleCenterY = barStartY + BAR_HEIGHT / 2;
for (int i = 0; i < list.size(); i++) {
int curX = getXPosition(i);
g.setColor(getPaintingModel().getColors().get(i));
g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
g.setColor(Color.black);
g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
String curS = list.get(i);
if (curS != null && curS.length() > 0) {
int startX = getStartXPosition(i);
int endX = getEndXPosition(i);
FontMetrics metrics = g.getFontMetrics();
Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
if (bounds.width < endX - startX && bounds.height < barStartY) {
g.setColor(Color.black);
g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
}
}
}
}
public static BufferedImage drawFaceAnnotations(BufferedImage originalImage, FaceAnnotation[] faceAnnotations) {
Graphics2D g = originalImage.createGraphics();
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Stroke stroke = g.getStroke();
Color color = g.getColor();
g.setStroke(new BasicStroke(3));
g.setColor(Color.YELLOW);
int radius = 2;
for (FaceAnnotation faceAnnotation : faceAnnotations) {
FaceAnnotation.BoundingBox bbox = faceAnnotation.getBoundingBox();
g.drawRect(bbox.getX(), bbox.getY(), bbox.getW(), bbox.getH());
for (FaceAnnotation.Landmark lm : faceAnnotation.getLandmarks()) {
g.fillOval(lm.getPosition().getX() - radius, lm.getPosition().getY() - radius,
2 * radius, 2 * radius);
}
}
g.setStroke(stroke);
g.setColor(color);
g.dispose();
return originalImage;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2d = (Graphics2D) g;
if (image != null) { //Selected
//Render settings
//g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//Border
g2d.setColor(Color.BLACK);
g2d.fillOval(x, y, getIconWidth() - 1, getIconHeight() - 1);
//Background
g2d.setColor(tagColor.getBackground());
g2d.fillOval(x + 1, y + 1, getIconWidth() - 3, getIconHeight() - 3);
//Image
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g.drawImage(image, x + 2, y + 2, null);
} else { //Not selected
//Render settings
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//Background
g2d.setColor(tagColor.getBackground());
g2d.fillRect(x, y, getIconWidth() - 1, getIconHeight() - 1);
//Border
g2d.setColor(Color.BLACK);
g2d.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 1);
//Text
g2d.setFont(new JLabel().getFont());
g2d.setColor(tagColor.getForeground());
g2d.drawString("a", x + 5, y + 11);
}
}
private void paintBar(Graphics2D g) {
List<String> list = getPaintingModel().getPositions();
int barStartY = getBarStartY();
g.setColor(BAR_COLOR);
g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);
int circleCenterY = barStartY + BAR_HEIGHT / 2;
for (int i = 0; i < list.size(); i++) {
int curX = getXPosition(i);
g.setColor(getPaintingModel().getColors().get(i));
g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
g.setColor(Color.black);
g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
String curS = list.get(i);
if (curS != null && curS.length() > 0) {
int startX = getStartXPosition(i);
int endX = getEndXPosition(i);
FontMetrics metrics = g.getFontMetrics();
Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
if (bounds.width < endX - startX && bounds.height < barStartY) {
g.setColor(Color.black);
g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
}
}
}
}
private void paintBar(Graphics2D g) {
List<String> list = getPaintingModel().getPositions();
int barStartY = getBarStartY();
g.setColor(BAR_COLOR);
g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);
int circleCenterY = barStartY + BAR_HEIGHT / 2;
for (int i = 0; i < list.size(); i++) {
int curX = getXPosition(i);
g.setColor(getPaintingModel().getColors().get(i));
g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
g.setColor(Color.black);
g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
String curS = list.get(i);
if (curS != null && curS.length() > 0) {
int startX = getStartXPosition(i);
int endX = getEndXPosition(i);
FontMetrics metrics = g.getFontMetrics();
Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
if (bounds.width < endX - startX && bounds.height < barStartY) {
g.setColor(Color.black);
g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
}
}
}
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Image image = Lizzie.config.theme.background();
try {
image = ImageIO.read(getClass().getResourceAsStream("/assets/countbackground.jpg"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int withtimes = (340 / image.getWidth(getOwner())) + 1;
int highttimes = (260 / image.getHeight(getOwner())) + 1;
for (int i = 0; i < highttimes; i++) {
for (int j = 0; j < withtimes; j++) {
g2.drawImage(image, image.getWidth(getOwner()) * j, image.getHeight(getOwner()) * i, null);
}
}
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.BLACK);
g2.setStroke(new BasicStroke(2f));
g2.fillOval(30, 58, 20, 20);
g2.setColor(Color.WHITE);
g2.fillOval(170, 58, 20, 20);
g2.setColor(Color.BLACK);
g2.setFont(new Font(Lizzie.config.uiFontName, Font.BOLD, 25));
if (allBlackCounts >= allWhiteCounts) {
g2.setColor(Color.BLACK);
g2.drawString(resourceBundle.getString("CountDialog.bigBlack"), 25, 50);
} else {
g2.setColor(Color.WHITE);
g2.drawString(resourceBundle.getString("CountDialog.bigWhite"), 25, 50);
}
g2.setFont(new Font(Lizzie.config.uiFontName, Font.BOLD, 20));
g2.drawString(
resourceBundle.getString("CountDialog.onBoardLead")
+ Math.abs(allBlackCounts - allWhiteCounts)
+ resourceBundle.getString("CountDialog.points"),
53,
50);
g2.setColor(Color.BLACK);
g2.setFont(new Font(Lizzie.config.uiFontName, Font.BOLD, 17));
g2.drawString(resourceBundle.getString("CountDialog.areaCount"), 95, 100);
g2.drawString(resourceBundle.getString("CountDialog.eat"), 95, 130);
g2.drawString(allBlackCounts + "", 32, 100);
g2.drawString(blackEat + "", 32, 130);
g2.setColor(Color.WHITE);
g2.drawString(allWhiteCounts + "", 172, 100);
g2.drawString(whiteEat + "", 172, 130);
button.repaint();
button2.repaint();
}
public void paint(Graphics2D g) { // object rendering
g.setColor(color);
g.fillOval(x * size, y * size, // upper left corner
size, size); // width and height
}
@Override
protected void paintBorder( Graphics2D g2 ) {
g2.fillOval( 0, 0, 15, 15 );
}
@Override
protected void paint(Component c, Graphics2D g, int x, int y) {
g.fillOval(x + 1, y + 1, 14, 14);
}
@Override
protected void paint(Component c, Graphics2D g, int x, int y) {
g.fillOval(x + 5, y + 5, 6, 6);
}