裂缝中的阳光。

等到黑夜翻面之后 会是新的白昼; 等到海啸退去之后 只是潮起潮落。

Welcome to JAVA!之Swing common features

12.8 Display a frame that contains six labels.Set the background of the labels to white.Set the foreground of the labels to black,blue,cyan,green,magenta,and orange,respectively,Set the border of each label to a line border with the yellow color,Set the font of each label to TimesRoman,bold,and 20 pixels.Set the text and tool tip text of each label to the name of its foreground color.

代码如下:

package com.ytu.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;

public class SwingCommFeature extends JFrame {
	public SwingCommFeature(){
		super();
		setSize(600,300);
		setLocationRelativeTo(null);
		setLayout(new GridLayout(2,3,5,10));
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		JLabel[] jlbs=new JLabel[6];
		LineBorder border = new LineBorder(Color.yellow,2);
		for (int i=0;i<jlbs.length;i++){
			
			jlbs[i]=new JLabel();
			jlbs[i].setBorder(border);
			jlbs[i].setBackground(Color.white);
			jlbs[i].setFont(new Font("TimesRoman",Font.BOLD,30));
			add(jlbs[i]);
			
		}
		jlbs[1].setText("black");
		jlbs[1].setForeground(Color.black);
		jlbs[1].setToolTipText("black");
		jlbs[2].setText("blue");
		jlbs[2].setForeground(Color.blue);
		jlbs[2].setToolTipText("blue");
		jlbs[3].setText("cyan");
		jlbs[3].setForeground(Color.cyan);
		jlbs[3].setToolTipText("cyan");
		jlbs[4].setText("green");
		jlbs[4].setForeground(Color.green);
		jlbs[4].setToolTipText("green");
		jlbs[5].setText("magenta");
		jlbs[5].setForeground(Color.magenta);
		jlbs[5].setToolTipText("magenta");
		jlbs[0].setText("orange");
		jlbs[0].setForeground(Color.orange);
		jlbs[0].setToolTipText("orange");
		setVisible(true);
	}
	
	public static void main(String[] args)
	{
		new SwingCommFeature();
	}
}
运行结果:


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Liuchang54/article/details/49892553
个人分类: JAVA学习笔记
上一篇蓝桥杯在线测试之入门练习(JAVA)
下一篇Welcome to JAVA!之displaying a checkerboard
想对作者说点什么? 我来说一句

Java Swing源文件

2010年03月23日 225KB 下载

java swing 日期控件

2010年08月26日 4KB 下载

没有更多推荐了,返回首页

关闭
关闭