j_slider.java.bak

来自「一个十分好的java基础学习的课件」· BAK 代码 · 共 57 行

BAK
57
字号
// ////////////////////////////////////////////////////////
// 
// J_Slider.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
//      Example of JSlider.
// ////////////////////////////////////////////////////////
// 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.*;
import javax.swing.event.*;

public class J_Slider extends JFrame
{
    private JLabel    m_label  = new JLabel( "0" );
    private JSlider   m_Slider = new JSlider(JSlider.HORIZONTAL, 0, 30, 0);

    public J_Slider( )
    {
        super( "Example of JSlider" );
        Container container = getContentPane( );
        container.setLayout( new FlowLayout( ) );      
        
        container.add( m_label );
        container.add( m_Slider );
        m_Slider.addChangeListener(new ChangeListener( ) // Register event handler
            {// anonymous inner class to handle events
                public void stateChanged(ChangeEvent e)
                {
                    int i= ((JSlider)e.getSource( )).getValue( );
                    m_label.setText( new Integer(i).toString( ) );
                } // End of method: stateChanged
            } // End of anonymous inner class (ChangeListener)
        ); // End of invoking addChangeListener

        setSize( 220, 80 );
        setVisible( true );
    } // End of constructor: J_Slider( )
    
    public static void main( String args[] )
    { 
        J_Slider app = new J_Slider( );
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    } // End of method: main

} // End of class: J_Slider

⌨️ 快捷键说明

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