Increased Display Text font to 14

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-04-05 11:32:55 -04:00
parent 45c083beda
commit b7ce8d1f37

View File

@@ -22,7 +22,9 @@ package com.RickBarrette.asteroids;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JPanel;
@@ -36,6 +38,7 @@ public class Display extends JPanel {
private AsteroidGame mGame;
private Container mContainer;
private String mText;
private Font mFont;
/**
* Creates a new Dispay
@@ -48,6 +51,9 @@ public class Display extends JPanel {
mContainer = c;
this.setBackground(new Color(0, 0, 0));
mContainer.add(this, BorderLayout.CENTER);
int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
int fontSize = (int)Math.round(14.0 * screenRes / 72.0);
mFont = new Font("Arial", Font.PLAIN, fontSize);
}
/**
@@ -58,10 +64,6 @@ public class Display extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(mText != null){
g.setColor(Color.ORANGE);
g.drawString(mText, (this.getWidth() / 2) - ((int) g.getFontMetrics().getStringBounds(mText, g).getWidth() / 2), this.getHeight() /2 );
}
/*
* Move & Draw the world's objects
@@ -80,6 +82,15 @@ public class Display extends JPanel {
if(item instanceof Drawable)
((Drawable) item).draw(g);
}
/*
* draw the text to be displayed
*/
if(mText != null){
g.setColor(Color.ORANGE);
g.setFont(mFont);
g.drawString(mText, (this.getWidth() / 2) - ((int) g.getFontMetrics().getStringBounds(mText, g).getWidth() / 2), this.getHeight() /2 );
}
}
public void setDisplayText(String string) {