how to adjust the size on a graphic component
So im trying to adjust the size on this graphic component code anyone have any ideas?
Code :
public class DisplayComponent extends JComponent
{
private boolean hasLetter = false;
private GameEngine game;
public void paintComponent(Graphics g)
{
// Recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
Line2D.Double bottom = new Line2D.Double(100, 500, 600, 500);
g2.draw(bottom);
Line2D.Double side = new Line2D.Double(200, 500, 200, 100);
g2.draw(side);
Line2D.Double top = new Line2D.Double(200, 100, 450, 100);
g2.draw(top);
Line2D.Double hang = new Line2D.Double(450, 100, 450, 150);
g2.draw(hang);
//EVERYTHING BELOW IM TRYING TO ADJUST
String newWord = game.getGuessWord();
g2.drawString(newWord, 350, 600);
}
Re: how to adjust the size on a graphic component
Re: how to adjust the size on a graphic component
The String newWord contains a string like(_ _ _ _) and what im trying to do is make whatever is in the variable newWorld display on the JFrame, to be bigger font.
http://i268.photobucket.com/albums/j...52/problem.png
Re: how to adjust the size on a graphic component
See Graphics.setFont. If you wish to just change the current font, you can simply call getFont().deriveFont(fontizeasfloat) and pass that to setfont.
Re: how to adjust the size on a graphic component
ok here is my new code, yet it still doesnt seem to be changing
Code :
public void paintComponent(Graphics g)
{
// Recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
Line2D.Double bottom = new Line2D.Double(100, 500, 600, 500);
g2.draw(bottom);
Line2D.Double side = new Line2D.Double(200, 500, 200, 100);
g2.draw(side);
Line2D.Double top = new Line2D.Double(200, 100, 450, 100);
g2.draw(top);
Line2D.Double hang = new Line2D.Double(450, 100, 450, 150);
g2.draw(hang);
//EVERYTHING BELOW IM TRYING TO ADJUST
String newWord = game.getGuessWord();
Font font = getFont().deriveFont(200);//<<<<<<<<<<<<NEW LINE
g2.setFont(font);//<<<<<<<<<<<<<<<<<<<<<<<<<NEW LINE
g2.drawString(newWord, 350, 600);
}
Re: how to adjust the size on a graphic component
Read the API for deriveFont, as I vaguely indicated in my post above to change the font size the parameter must be a float. (eg deriveFont(200f))
Re: how to adjust the size on a graphic component
Thanks that worked just like how i was wanting it, but why does it work when i just add an "f" at the end of that number. I mean i understood it had to be a float but my understanding was that floats and doubles are relatively the same in the way, only real difference is that float is like a point on a graph by itself. But just putting an "f" at the end? what does that mean? im relatively new to programming so forgive me if it sounds a little naive :). Thanks for helping nevertheless
Re: how to adjust the size on a graphic component
Have you read the API for Font? What are the overloads of DeriveFont and what Type of parameters do they take?
db
Re: how to adjust the size on a graphic component
Also go through
Lexical Structure
db