Java Swing界面编程(3)---标签组件(JLabel)

时间:2014-06-04 23:43:11   收藏:0   阅读:429
package com.beyole.util;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class test2 {
	public static void main(String[] args) {
		JFrame frame = new JFrame("welcome to mldn");// 实例化窗口程序
		JLabel label = new JLabel("MLDN", JLabel.CENTER);// 实例化对象,使用居中对齐
		Font fnt=new Font("Serief",Font.ITALIC,28);
		label.setFont(fnt);
		label.setForeground(Color.red);
		frame.add(label);// 向容器中加入组件
		Dimension dimension=new Dimension();//实例化dimension
		dimension.setSize(200,70);//设置大小
		frame.setSize(dimension);//设置组件大小
		frame.setBackground(Color.white);//设置背景色
		Point point=new Point(300,200);//设置显示的坐标点
		frame.setLocation(point);//设置窗体显示 的位置
		frame.setVisible(true);//让组件显示
	}
}

设置标签的颜色和字体,用到的是先设置标签的显示字体,先new了一个Font对象,然后使用标签的setFont方法设置字体,颜色则用setForeground方法。

程序截图:bubuko.com,布布扣

Java Swing界面编程(3)---标签组件(JLabel),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!