Welcome to JAVA!之Swing common features

原创 2015年11月17日 20:36:10

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


版权声明:本文为博主原创文章,未经博主允许不得转载。

Welcome to JAVA!(第一课课后练习)

1.16 The following program is wrong.Reorder the lines so that the program displays mornig followed b...

Welcome to JAVA!(第3章课后习题)

3.1

Welcome to JAVA!(第4章课后习题)

4.1* Write a program that reads an unspecified number of integers,determines how many postive and ne...

Welcome to JAVA!(第8章课后习题)

8.1Following the example of the Circle class in &8.2,design a class named Rectangle to represent a r...

Welcome to JAVA!(第二课课后练习)

2.9 Show the output. public class Main { public static void main(String[] args) { System.out.pr...

Award_eL_IPC_103_Welcome to IP Networking

  • 2013年09月14日 20:47
  • 208KB
  • 下载

java 批量文件编码转换 GBK to UTF-8(swing界面)

代码后上需要注意文件编码GBK,内容编码UTF-8的装换,反之亦然!
  • hj_545
  • hj_545
  • 2011年04月21日 10:40
  • 2834

Welcome to jquery-confirm

  • 2016年01月15日 15:07
  • 558KB
  • 下载

Welcome to beifang ethnic university.

  • 2011年06月11日 11:40
  • 21KB
  • 下载

4Dresult 100% Welcome Bonus Up to MYR888!

Online 4Dresult Malaysia and iBET Online Casino Malaysia have a New First Deposit 100% Welcome Bonus...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Welcome to JAVA!之Swing common features
举报原因:
原因补充:

(最多只允许输入30个字)