Source of UnicodeTextViewer.java


  1: 
  2: package unicode; 
  3: 
  4: import java.awt.*;
  5: import java.awt.event.*;
  6: import java.io.*; 
  7: import javax.swing.*;
  8: 
  9: public class UnicodeTextViewer extends JPanel { 
 10:   
 11:   public UnicodeTextViewer(String filename, String enc) {
 12:     setLayout(new BorderLayout());
 13:     JTextArea textarea = new JTextArea(40, 80); 
 14:     textarea.setEditable(false); 
 15:     //textarea.setFont(new Font("Monospaced", Font.BOLD, 16)); 
 16:     //textarea.setFont(new Font("AR PL KaitiM GB", Font.BOLD, 16)); 
 17:     textarea.setFont(new Font("AR PL SungtiL GB", Font.BOLD, 24)); 
 18:     add(new JScrollPane(textarea), BorderLayout.CENTER); 
 19:     try {
 20:       BufferedReader in = 
 21:           new BufferedReader(
 22:           new InputStreamReader(new FileInputStream(filename), enc)); 
 23:       String line; 
 24:       while ((line = in.readLine()) != null) {
 25:         textarea.append(line + "\n"); 
 26:       }
 27:     } catch (IOException e) {}
 28:   }
 29: 
 30:   /*
 31:    *  java unicode.UnicodeTextViewer Lincoln.txt ISO-8859-1 
 32:    *  java unicode.UnicodeTextViewer hlmg001.gb GB2312
 33:    */
 34:   public static void main(String args[]) {
 35:     if (args.length >= 2) {
 36:       JFrame frame = new JFrame();
 37:       frame.setTitle("Unicode Text Viewer: " + 
 38:                      args[0] + " [" + args[1] + "]");
 39:       frame.setBackground(Color.lightGray);
 40:       frame.getContentPane().setLayout(new BorderLayout());
 41:       frame.getContentPane().add(new UnicodeTextViewer(args[0], args[1]), BorderLayout.CENTER);
 42:       frame.setSize(400, 300);
 43:       frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
 44:       frame.setVisible(true);
 45:     }
 46:   }
 47: 
 48: }