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

📄 j_text.java.bak

📁 一个十分好的java基础学习的课件
💻 BAK
字号:
// ////////////////////////////////////////////////////////
// 
// J_Text.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
//      Demonstrating classes JTextField and JPasswordField.
// ////////////////////////////////////////////////////////
// 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 java.awt.event.*;
import javax.swing.*;

public class J_Text extends JFrame
{
    private JTextField [] m_textField = {
        new JTextField("Shown  Text:", 8), new JTextField( "Shown", 15),
        new JTextField("Hidden Text:", 8), new JPasswordField( "Hidden", 15)};

    // set up GUI
    public J_Text( )
    {
        super( "Example of JTextField and JPasswordField" );
    
        Container container = getContentPane( );
        container.setLayout( new FlowLayout( ) );
    
        // construct textfield with default sizing
        m_textField[0].setEditable( false );
        m_textField[2].setEditable( false );
        
        for (int i= 0; i< 4; i++)
            container.add( m_textField[i] );
        
        J_Handler handler = new J_Handler( ); // register event handlers
        m_textField[1].addActionListener( handler );
        m_textField[3].addActionListener( handler );
        
        setSize( 325, 100 );
        setVisible( true );
    } // End of method: J_Text
    
    // private inner class for event handling
    private class J_Handler implements ActionListener
    {
        // process text field events
        public void actionPerformed( ActionEvent event )
        {
            String s="";
            if ( event.getSource( ) == m_textField[1] )
                s = "Shown Text: " + event.getActionCommand( );
            else if (event.getSource( ) == m_textField[3])
                s = "Hidden text: " + new String(((JPasswordField)m_textField[3]).getPassword( ));
            JOptionPane.showMessageDialog( null, s );
        } // End of method: actionPerformed
    } // End of class: J_Handler

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

⌨️ 快捷键说明

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