【发布时间】:2015-11-05 13:20:26
【问题描述】:
这是下面的代码,由于在 JLabel 上应用了 setfont() 函数,我收到了错误。 setFont() 的语法似乎是正确的。
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Font {
public static void main(String Args[])
{
JFrame frame=new JFrame();
frame.setBounds(100, 100, 450, 300);
JLabel string1=new JLabel("Some Text");
string1.setBounds(100,100,450,300);
JTextField txt=new JTextField("add");
string1.setFont (new Font("Arial", Font.Bold, 12));
frame.setVisible(true);
frame.add(string1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
错误是:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method setFont(java.awt.Font) in the type JComponent is not applicable for the arguments (Font)
Bold cannot be resolved or is not a field
at Font.main(Font.java:13)
【问题讨论】: