码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-06-04 23:43:11      阅读:429      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   code   java   a   

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

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

标签:c   class   blog   code   java   a   

原文地址:http://blog.csdn.net/xuejiawei123/article/details/27107403

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!