隨筆-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
          主站蜘蛛池模板: 刚察县| 阿拉善右旗| 玉环县| 张家口市| 武功县| 元阳县| 酉阳| 边坝县| 韩城市| 阳城县| 桂阳县| 凤山县| 图木舒克市| 图们市| 百色市| 宜宾市| 布尔津县| 吉木乃县| 曲阳县| 岢岚县| 阳高县| 苏尼特右旗| 灯塔市| 新营市| 镇宁| 神农架林区| 韶关市| 宜兴市| 通州区| 麻城市| 顺平县| 含山县| 蓝田县| 讷河市| 来宾市| 仁布县| 中牟县| 皋兰县| 伊宁市| 扬中市| 台州市|