隨筆-3  評論-1  文章-13  trackbacks-0

          import java.awt.BorderLayout;
          import java.awt.Container;
          import java.awt.event.ActionEvent;
          import java.awt.event.ActionListener;
          import java.io.File;
          import java.io.FileInputStream;
          import java.io.FileNotFoundException;
          import java.io.IOException;

          import javax.swing.JButton;
          import javax.swing.JFileChooser;
          import javax.swing.JFrame;
          import javax.swing.JScrollBar;
          import javax.swing.JScrollPane;
          import javax.swing.JTextPane;

          public class jfileChooser extends JFrame implements ActionListener {
           Container con;
           JTextPane textpane;
           JButton button;
           JScrollPane scroll;
           FileInputStream filestream;
           JFileChooser choser=new JFileChooser();
           public  jfileChooser(){
            textpane=new JTextPane();
            button=new JButton("ok");
            scroll=new  JScrollPane(textpane);
            con=this.getContentPane();
            con.add(scroll,BorderLayout.CENTER);
            con.add(button,BorderLayout.SOUTH);
            button.addActionListener(this);
            this.setExtendedState(JFrame.MAXIMIZED_BOTH);
            setVisible(true);
           }

           public void actionPerformed(ActionEvent e) {
            // TODO 自動生成方法存根
            if(e.getSource()==button){
             int state= choser.showOpenDialog(null);
             File file=choser.getSelectedFile();
             if(file!=null && state==JFileChooser.APPROVE_OPTION){
              try {
               filestream=new FileInputStream(file);
              } catch (FileNotFoundException e1) {
               // TODO 自動生成 catch 塊
               e1.printStackTrace();
              }
              try {
               textpane.read(filestream,this);
              } catch (IOException e1) {
               // TODO 自動生成 catch 塊
               e1.printStackTrace();
              }
             }
            }

           }
           public static void main(String para[]){
            jfileChooser chosershili=new jfileChooser();
            //chosershili.pack();
           }

          }

          posted on 2007-07-16 12:46 lcgxc 閱讀(3203) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 靖西县| 永丰县| 南华县| 定日县| 沭阳县| 和龙市| 罗定市| 德惠市| 集贤县| 临沧市| 宝应县| 青阳县| 南木林县| 涿州市| 平潭县| 白沙| 五大连池市| 民勤县| 广南县| 威远县| 上杭县| 霍林郭勒市| 北辰区| 遂溪县| 乾安县| 云梦县| 三江| 海南省| 宁城县| 鹿泉市| 民和| 凤台县| 琼海市| 迁西县| 辽阳县| 临桂县| 中山市| 任丘市| 新余市| 龙门县| 三亚市|