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();
	}
}
运行结果:


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值