<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 39,  comments - 263,  trackbacks - 0

    package publictool.cellEditor;

    import java.awt.Component;
    import java.awt.Frame;
    import java.awt.HeadlessException;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.EventObject;

    import javax.swing.AbstractCellEditor;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFileChooser;
    import javax.swing.JTable;
    import javax.swing.table.TableCellEditor;

    import rootwindow.ValueMap;

    import com.borland.jb.io.InputStreamToByteArray;

    public class ImageCellEditor extends AbstractCellEditor implements
      TableCellEditor, ActionListener {
     // 鼠標點擊次數
     public int CLICKCOUNT = 2;

     JButton button;

     // button 命令的名稱
     protected static final String EDIT = "CELLEDITOR";

     // 對話框中確定的命令要是"OK"
     protected static final String DIALOG_OK = "OK";

     // 最終的返回一個object
     Object curobject;

     // 所有的彈出式窗口都必須是Dialog的子類
     // 而且必須有getSelectInPut
     // CellEditorDialog dialog1;

     JDialog dialog1;

     ValueMap valuemap;

     Frame frame;

     JFileChooserx jfc;

     public ImageCellEditor(Frame frame, ValueMap valuemap) {
      // super(frame, valuemap);
      init();
     }

     public void init() {
      System.out.println("sss1");
      button = new JButton();
      button.setActionCommand(EDIT);
      button.addActionListener(this);
      button.setBorderPainted(false);
      /*
       * dialog1 = new CellEditorDialog(frame, "", true, valuemap, "select
       * bcode,bname from bcode", "bname", this, null);
       */

      jfc = new JFileChooserx();
      dialog1 = jfc.createDialog(frame);
      jfc.addActionListener(this);

     }

     public Object getCellEditorValue() {

      System.out.println("3");
      return curobject;

     }

     public Component getTableCellEditorComponent(JTable table, Object value,
       boolean isSelected, int row, int column) {
      System.out.println("4");
      // curobject =jfc .getSelectedFile();
    /*
      File file = jfc.getSelectedFile();
      InputStream is = null;
      InputStreamToByteArray imputs = null;
      byte[] b = new byte[102400];
      if (file != null) {
       try {
        System.out.println("5");
        is = new FileInputStream(file);
        is.read(b);

        imputs = new InputStreamToByteArray(b);
        // imputs = (InputStreamToByteArray)is;

       } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
       }
        curobject = imputs;
       //curobject = null;
      }*/
      curobject = value;
      System.out.println("value = "+value);
      System.out.println("getTableCellEditorComponent"+curobject);
      return button;

     }

     // 默認鼠標雙擊才可以編輯
     public boolean isCellEditable(EventObject anEvent) {
      if (anEvent instanceof MouseEvent) {
       return ((MouseEvent) anEvent).getClickCount() >= CLICKCOUNT;
      }
      return true;
     }

     /**
      * Handles events from the editor button and from the dialog's OK button.
      */
     public void actionPerformed(ActionEvent e) {
      System.out.println("command=" + e.getActionCommand());
      if (EDIT.equals(e.getActionCommand())) {
       // The user has clicked the cell, so
       // bring up the dialog.

       dialog1.setVisible(true);

       // Make the renderer reappear.
       fireEditingStopped();
       System.out.println("1");
      } else if ("ApproveSelection".equals(e.getActionCommand())) { // User
       // pressed
       // dialog's
       // "OK"
       // button.
       File file = jfc.getSelectedFile();
       if (file != null) {
        InputStream is = null;
        InputStreamToByteArray imputs = null;
        byte[] b = new byte[102400];
        try {
         System.out.println("6");
         is = new FileInputStream(file);
         // InputStreamToByteArray imputs = new
         // InputStreamToByteArray(null);
         is.read(b);
         imputs = new InputStreamToByteArray(b);
         curobject = imputs;
         // imputs = (InputStreamToByteArray)is;
         // b = new byte[1024];
         // is.read(b);
        } catch (Exception e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
        }
       }
       dialog1.dispose();
       

      }
       else if ("CancelSelection".equals(e.getActionCommand())) {
      
       dialog1.dispose();
      
       }
     }

     class JFileChooserx extends JFileChooser implements ActionListener {
      JDialog dialog = null;

      public JFileChooserx() {
       super();
      }

      public JDialog createDialog(Component parent) throws HeadlessException {

       return dialog = super.createDialog(parent);
      }

      public void actionPerformed(ActionEvent e) {
       
       if ("CancelSelection".equals(e.getActionCommand())) {
        dialog.dispose();
       }
      }
     }
    }

    有幾個地方要注意JFileChooser的createDialog(Component parent)是protected的,我要覆蓋它
    jdbtable里存圖片是用InputStreamToByteArray 來存儲的,這里我還有個問題如何把讀出來的圖片,存到數據庫中。
    我現在是讀取圖片--放在byte[]中--數據庫,這樣一來我不知道byte要設置多大的長度,在控制臺老報“Premature end of JPEG file”
    但是這不是一個異常。

    posted on 2005-10-23 23:34 nake 閱讀(968) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2005年10月>
    2526272829301
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    常用鏈接

    留言簿(18)

    我參與的團隊

    隨筆檔案(39)

    收藏夾(1)

    搜索

    •  

    積分與排名

    • 積分 - 451272
    • 排名 - 119

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 日韩在线看片免费人成视频播放| 亚洲国产精品视频| 国产成人99久久亚洲综合精品| 亚洲人成电影亚洲人成9999网| 亚洲国产精品无码观看久久| 成全视频高清免费观看电视剧| 成年女性特黄午夜视频免费看| 亚洲宅男天堂在线观看无病毒 | 亚洲欧洲久久av| 亚洲欧洲国产经精品香蕉网| 成人a毛片视频免费看| 免费观看激色视频网站bd| 亚洲日韩人妻第一页| 2019亚洲午夜无码天堂| 成人A片产无码免费视频在线观看 成人电影在线免费观看 | 免费视频成人国产精品网站| 91久久青青草原线免费| 亚洲精品岛国片在线观看| 亚洲三级在线观看| 男人进去女人爽免费视频国产| 国产成人无码区免费A∨视频网站 国产成人涩涩涩视频在线观看免费 | 女人被男人躁的女爽免费视频| 亚洲av日韩av激情亚洲| 免费激情网站国产高清第一页| 免费在线观看视频网站| 亚洲国产另类久久久精品黑人| 亚洲AV日韩综合一区| free哆啪啪免费永久| 亚洲色无码专区在线观看| 国产亚洲漂亮白嫩美女在线| 男女超爽刺激视频免费播放| 国产成人精品日本亚洲| 免费人成网站永久| 免费黄色网址入口| 亚洲国产精品白丝在线观看| 国产白丝无码免费视频| 亚洲欧洲自拍拍偷午夜色无码| 另类图片亚洲校园小说区| 成人免费视频试看120秒| 亚洲最大的视频网站| 久久狠狠躁免费观看2020|