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

📄 textexamples.java

📁 北京大学出版社的
💻 JAVA
字号:
package examples.windows;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
/** An example class used to demonstrate the use of 
  * the JTextField and JTextArea components
  */
public class TextExamples extends JFrame {
   /** Class constructor method
     * @param titleText Window's title bar text
     */
   public TextExamples( String titleText ) {
      super( titleText );
      addWindowListener( new WindowCloser() );
      final JTextArea upper = new JTextArea();
      final JTextArea lower
         = new JTextArea( upper.getDocument() );
      JScrollPane upperScroll = new JScrollPane( upper );
      JScrollPane lowerScroll = new JScrollPane( lower );
      JSplitPane sp
         = new JSplitPane( JSplitPane.VERTICAL_SPLIT,
                           upperScroll,
                           lowerScroll );
      sp.setOneTouchExpandable( true );
      sp.setDividerLocation( 0.5 );

      final JTextField fName = new JTextField();
      fName.setToolTipText( "Enter a file name" );
      fName.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
               if ( fName.getText() != null ) try {
                  FileReader fr
                     = new FileReader( fName.getText() );
                  upper.setText( "" );
                  char[] buffer = new char[4096];
                  int count = fr.read( buffer, 0,
                                       buffer.length );
                  while ( count != -1 ) {
                     upper.append( new String( buffer, 0,
                                               count ) );
                     count = fr.read( buffer, 0,
                                      buffer.length );
                  }
               } catch( IOException ioe ) {
                  System.out.println( ioe );
               }
            }
         }
      );

      JPanel entry = new JPanel( new BorderLayout() );
      entry.add( new JLabel( "File: " ),
                 BorderLayout.WEST );
      entry.add( fName, BorderLayout.CENTER );
      getContentPane().add( entry, BorderLayout.NORTH );
      getContentPane().add( sp, BorderLayout.CENTER );
      setSize( 500, 400 );
      fName.requestFocus();
      setVisible( true );
   }

   /** The test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      new TextExamples( "Example Text Components" );
   }
}

⌨️ 快捷键说明

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