我写了一个 APPLET 用于WEB 的FTP上传,
当用户点击 上传 按纽 以后, 触发一个线程进行上传,
我想在上传过程 中动态控制 APPLET 的进度条,但是
调试 老出错,程序一到控制APPLET 进度条 的地方就报
NULL POINT 异常。

解决方案 »

  1.   


    public class Face extends JApplet implements ActionListener
    {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public void init()
    {
    //frm=new Face();
    setLayout(new FlowLayout());
    //JTabbedPane tabPane=new JTabbedPane();
    Container cr = getContentPane();

    //JFileChooser jfc=new JFileChooser();
    jfc.setCurrentDirectory(new File("d:\\"));

    //文件选择器的初始目录定为d盘   
           
    //JProgressBar 
            
        //下面设定标签等的出现位置和高宽   
    //pathText.setSize(100, 20);
            cr.add(label1);   
            cr.add(pathText);   
            cr.add(jn);   
            cr.add(up);
            cr.add(jp);
            //cr.add(jfc);   
            //tabPane.add("目录/文件选择",cr);//添加布局1   
           

        jn.addActionListener(this);
        up.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(jn))
    {

    jfc.setFileSelectionMode(1);
    int state=jfc.showOpenDialog(null);//此句是打开文件选择器界面的触发语句   
                if(state==1){   
                    return;//撤销则返回   
                }   
                else{   
                    File f=jfc.getSelectedFile();//f为选择到的文件   
                    pathText.setText(f.getAbsolutePath());   
                    label1.setText(f.getAbsolutePath());
                    System.out.println(f.getAbsolutePath());
                }   
    }
    if(e.getSource().equals(up))
    {
    if(pathText.getText().length()>=1)
    {
    up.setEnabled(false);
    jn.setEnabled(false);
    FileSize = new File(pathText.getText()).length();
    UploadFile i = new UploadFile("35zs.com","robin","robin",frm,new File(pathText.getText()));
    i.start();
    }else
    {

    }
    }

    }
    /*public File getPath(String path)
    {
    String[] pa  = path.split("\\");
    path.replace("", newChar)
    }*/
        static Face frm;
    JButton up= new JButton("开始上传");
    JTextField pathText= new JTextField();
        public JButton jn=new JButton("...");
    public JLabel label1=new JLabel("选择文件");
    JProgressBar jp= new JProgressBar();
    float CompletaSize =0;
        float FileSize ;

     JFileChooser jfc=new JFileChooser();//文件选择器   
     
     public void updateGress()
     {
     CompletaSize=CompletaSize+1;
     int percent = (int) (( CompletaSize / FileSize) * 10000F);
            jp.setValue(percent);
            System.out.println("================================================="+percent);
            jp.setString(CompletaSize / 1024L + "/" + FileSize / 1024L
                    + " kB");
            
            repaint();  }
     
    }
    线程 里面 调用 了APPLET的 updateGress()方法
      

  2.   

    按照默认applet是不允许读取文件的,这个不知道改了没有。
      

  3.   


    这个我还在调试阶段,以后会加 数字签名, 让APPLET 在客户端 可以读取客户端 文件
      

  4.   

    主要问题是进度条如何实现(也就是说在触发的线程中 如何才能回调APPLET 让APPLET的进度条 改变);
    上传都没有问题的, 希望大家多多帮忙,比较棘手哈,我都搞了好几天了,心情 烦躁哦!!!!!
      

  5.   

     String url ;
         String user ;
         String pwd ;
         Face fc;
         File localDir;
         FTPClient ftp;
    public UploadFile(String url,String user ,String pwd,Face fc,File localDir)
    {
    this.url=url;
    this.user=user;
    this.pwd=pwd;
    this.fc=fc;
    this.localDir=localDir;
    }

    public void run()
    {
    if(login()){
    try{
    uploadFile(ftp);
    }catch(Exception e)
    {
    e.printStackTrace();
    }finally
    {
    disconnectFtpServer(ftp);
    System.out.println("all done");

    //fc.jn.setEnabled(true);就是这两句报的错,         //fc.label1.setText("完成");去掉以后,上传就正常了         
    }
    }
    }线程的部分代码; 
      

  6.   

    updateGress这个方法在哪调用的?
      

  7.   

    disconnectFtpServer(ftp);
                    System.out.println("all done");
                    
                    //fc.jn.setEnabled(true);就是这两句报的错,                
    //fc.label1.setText("完成");去掉以后,上传就正常了fc.updateGress();