我将ttf
字体加载到Java中,我知道它正在阅读它,因为它没有给我一个错误,但它不会真的读取字体,因为它只是给我一条线。
这是我的Screen类使用字体的代码:
public class BLANKMainMenuScreen extends JPanel {
private JButton playButton;
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = d.width;
int screenHeight = d.height;
public ImageIcon greenButton = new ImageIcon("resources/menubuttons/GreenButton.png");
public ImageIcon redButton = new ImageIcon("resources/menubuttons/RedButton.png");
public BLANKMainMenuScreen() throws FontFormatException, IOException {
setLayout(new GroupLayout(this));
playButton = new JButton("Play!");
playButton.setIcon(greenButton);
playButton.setBorderPainted(false);
playButton.setContentAreaFilled(false);
playButton.setFocusPainted(false);
playButton.setActionCommand("/mainMenuPlayButton");
playButton.setFont(Font.createFont(Font.TRUETYPE_FONT, new File("resources/font/cubic.ttf")));
playButton.setBounds(screenWidth / 2 - 100, screenHeight / 3 - 50, 200, 100);
playButton.setRolloverEnabled(true);
playButton.setRolloverIcon(redButton);
playButton.setHorizontalTextPosition(SwingConstants.CENTER);
add(playButton);
}
public void addActionListener(JButton b, ActionListener listener) {
b.addActionListener(listener);
}
public void removeActionListener(JButton b, ActionListener listener) {
b.removeActionListener(listener);
}
@Override
public Dimension getPreferredSize() {
return Toolkit.getDefaultToolkit().getScreenSize();
}
我不知道为什么它只会向我呈现一条线,但确实如此。