im new to awt and string, and I am trying to draw a string but I dont know how to size it.
This is what I have done:
public void draw(Graphics g) {
g.drawString("$", x, y);}
So the $ comes up, but it is very small, I want to make the string same as an oval I made
g.fillOval(applex,appley,unitSize,unitSize);
Any tips? Thank you
CodePudding user response:
Set a font to increase the size. Check out the Font class in the Javadoc to see the options.
g.setFont(new Font("Arial", Font.BOLD, 72));
Also, if you cast g
to Graphics2D
and use RenderingHints
, you can turn on anti-aliasing
to visually smooth out your shapes, etc.
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);