⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j_label.java.bak

📁 一个十分好的java基础学习的课件
💻 BAK
字号:
// ////////////////////////////////////////////////////////
// 
// J_Label.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
//  Demonstrating the JLabel class.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
//     Jun-Hai Yong. Programming in Java. 
//     Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
//     雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no 
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////

import java.awt.*;
import javax.swing.*;

public class J_Label extends JFrame
{
    public J_Label( )// set up GUI
    {
        super( "Example of JLabel" );
        String [] s={"Label 1: with text",
                               "Label 2: with text and icon",
                               "Label 3: with icon and text(at bottom)"};
        Icon [] ic  = {null, new ImageIcon( "img1.gif" ), new ImageIcon( "img2.gif" )};
        int  [] ih  = {0, JLabel.LEFT,   JLabel.CENTER};
        int  [] iv  = {0, JLabel.CENTER, JLabel.BOTTOM};
        
        Container container = getContentPane( ); // get content pane and set its layout
        container.setLayout( new FlowLayout(FlowLayout.LEFT) );
        
        for (int i= 0; i< 3; i++) // Create three labels.
        {
            JLabel aLabel = new JLabel( s[i] , ic[i], JLabel.LEFT);
            if (i>0)
            {
                aLabel.setHorizontalTextPosition(ih[i]);
                aLabel.setVerticalTextPosition  (iv[i]);
            }
            aLabel.setToolTipText( "This is Label" + (i+1));
            container.add( aLabel );
        } // End of loop: for
        setSize( 250, 220 );
        setVisible( true );
    } // End of method: J_Label

    public static void main( String args[] )
    { 
        J_Label application = new J_Label( );
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    } // End of method: main

}  // end class J_Label

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -