<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

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 青青草国产免费久久久下载| 色欲色香天天天综合网站免费| 在线观看的免费网站| 亚洲日韩精品一区二区三区| 国产乱弄免费视频| 美女羞羞免费视频网站| 久久人午夜亚洲精品无码区| 精品国产污污免费网站aⅴ| 亚洲国产精品久久| 精品熟女少妇a∨免费久久| 91亚洲精品第一综合不卡播放| 日韩精品人妻系列无码专区免费| 亚洲国产精品久久久久| 91高清免费国产自产| 亚洲色精品VR一区区三区| 精品免费国产一区二区三区| 最好2018中文免费视频| 亚洲人JIZZ日本人| 2021国内精品久久久久精免费 | 成人黄18免费视频| 亚洲国产成人久久精品大牛影视 | 免费一级特黄特色大片在线观看| 男人和女人高潮免费网站| 久久伊人亚洲AV无码网站| jizz在线免费播放| 国产成人免费视频| 天堂在线免费观看| 美女网站在线观看视频免费的 | 1000部羞羞禁止免费观看视频 | 伊人久久亚洲综合影院| 国产乱妇高清无乱码免费| 亚洲一区爱区精品无码| 91嫩草免费国产永久入口| 亚洲av永久无码| 亚洲精品蜜桃久久久久久| 日本亚洲免费无线码| 一边摸一边桶一边脱免费视频| 亚洲天堂中文字幕| 国产午夜无码视频免费网站| 精品视频一区二区三区免费| 亚洲一线产品二线产品|