Welcome to JAVA!之Swing common features
来源:互联网 发布:淘宝平台运营思路 编辑:程序博客网 时间:2024/06/02 05:48
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 0
- Welcome to JAVA!之Swing common features
- JAVA 12.8(Swing common features)
- Welcome to JAVA!之Person类
- Welcome to JAVA!之displaying a checkerboard
- java ---- welcome to java Applet
- [Java] Welcome to Artifactory 使用说明
- [Java] Welcome to Artifactory 使用说明
- Java学习第一课--Welcome to Java!
- java学习开始,输出Welcome to Java!
- java 开始学习,输入Welcome to java
- luci自定义之welcome to luci
- Welcome to JAVA!(第一课课后练习)
- Welcome to JAVA!(第二课课后练习)
- Welcome to JAVA!(第五课课后练习)
- Welcome.java
- Welcome.java
- Welcome.java
- java之swing
- 各种树的应用
- Java 文件监控,实时监控文件加载
- hihocoder 1257 Snake Carpet 2015 ACM_ICPC 北京区域赛 I 题
- Android中DisplayMetrics 获取手机屏幕分辨率
- python中string字符串模块
- Welcome to JAVA!之Swing common features
- 小公司:美术与技术适配屏幕统一方案
- CALayer之绘图
- java继承&子父类成员域加载及执行过程
- textarea 在浏览器中固定大小和禁止拖动
- HTML-embed标签详解
- 预编译指令,也称作宏定义
- Eclipse设置自动生成注释
- 如果有人问你Java垃圾回收机制你这么答就好了!