日期:2014-05-20 浏览次数:21008 次
import javax.swing.*;
import java.awt.*;
public class Demo2 extends JFrame {
private JLabel[] lb=new JLabel[3];
public Demo2(String title){
super(title);
Container c=this.getContentPane();
c.setLayout(new FlowLayout());
// JLabel label = new JLabel("<font color='red' size='24'>文字</font>");
JLabel label = new JLabel("文字");
Font font=new Font("Monospaced",Font.BOLD,32);//设置字体格式和大小
label.setForeground(Color.RED);//设置前景色
label.setFont(font);
c.add(label);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args){
new Demo2("字体颜色实例");
}
}