java 中的图片上传

//点击上传个人照片
      if(e.getActionCommand().equals("上传个人照片")){
       JFileChooser chooser = new JFileChooser();
       // 设置当前文件夹
    chooser.setCurrentDirectory(file);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
    chooser.setFileFilter(filter);
          int returnVal = chooser.showOpenDialog(getContentPane());
          if (returnVal == JFileChooser.APPROVE_OPTION) {
     file= chooser.getSelectedFile();
     String message="你选择的图片是:"+chooser.getSelectedFile().getName();
     JOptionPane.showMessageDialog(this, message);
         showPeoplePicture();
       }
        }
     

 /**
   * 显示图片
   *
   */
    private void showWorkPicture() {
        if (file == null  ) {
   return;
     }
  PicturePanel canvas = null;
   {
   if (picLabel2.getComponentCount() > 0) {
    canvas = (PicturePanel) picLabel2.getComponent(0);
   } else {
    canvas = new PicturePanel();
    picLabel2.add(canvas, BorderLayout.CENTER);
   }
   canvas.setPath(file.getPath());
   canvas.repaint();
   picLabel2.repaint();
  } 
  panel.updateUI();
 }

 

你可能感兴趣的:(java,图片上传)