建立一个框架,设置文字的颜色,字体,大小和位置

import java.awt.*;
import javax.swing.*;
public class JFrameDemo {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        JFrame frame = new JFrame();
        Container contentPane = frame.getContentPane();

        Font f1 = new Font("黑体", Font.BOLD, 24);
        JButton l1 = new JButton("西藏民族大学");
        l1.setFont(f1);
        l1.setForeground(Color.red);
        contentPane.add(l1, BorderLayout.CENTER);


        Font f2 = new Font("宋体", Font.ITALIC, 16);
        JButton l2 = new JButton("信息工程学院");
        l2.setFont(f2);
        l2.setForeground(Color.blue);
        contentPane.add(l2, BorderLayout.NORTH);


        frame.setSize(300, 300);
        frame.setVisible(true);
    }
}

  

原文地址:https://www.cnblogs.com/zhouxiaoyue/p/14143050.html