You could just do...
g.setFont(pixel);
But you might have better sucess with
g.setFont(pixel.deriveFont(Font.BOLD, 36f));
Are variations of....
Also, don't dispose of a Graphics
context you did not create...
Graphics2D g2d = (Graphics2D)g;
/*...*/
// g.dispose();
Or
Graphics2D g2d = (Graphics2D)g.create();
/*...*/
g.dispose();
I'd also be loathed to override the paint
method. Assuming you're using something like JComponent
or JPanel
, you should use paintComponent
. If you're rendering directly yo a top level container (like JFrame
), then I wouldn't. There are issues with double buffering and frame borders that won't make your life fun...
I'm also concerned about new Timer(5, this)
- 5 milliseconds is close enough to 0 to make little difference. You'd be better of with something like 40
, which should give you something like 25fps or 17
which will give you roughly 60fps...