【发布时间】:2017-08-05 08:23:37
【问题描述】:
我有一个问题:我想创建一个小游戏,我必须制作一个如下所示的窗口:
当我试图改变“Fun With Words”的字体大小时,它没有改变......
我该怎么办?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JComponent;
public class GameWords extends JFrame
{
private static int W = 800 ;
private static int H = 600 ;
public GameWords ()
{
setTitle ( " Word Order Game " ) ;
setSize ( H , W ) ;
setLayout ( new FlowLayout() ) ;
setDefaultCloseOperation ( EXIT_ON_CLOSE ) ;
createContent () ;
setVisible ( true ) ;
}
public void createContent ()
{
JLabel heading = new JLabel (" Fun With Words ") ;
heading.setFont ( heading.getFont().deriveFont ( 26f ) );
heading.setPreferredSize ( new Dimension ( H , 4 * W ) ) ;
JLabel h1 = new JLabel ( " Hey Kids! Want to prictice your typing and word-ordering Skills ? \n" ) ;
add ( heading ) ;
add ( h1 ) ;
}
public static void main(String[] args)
{
new GameWords () ;
}
}
【问题讨论】: