2010-03-18 60 views
2

我使用netbeans6.7.1和phpMyAdmin的我的数据库来开发Java应用程序 来管理学生图像记录 我想通过浏览上传照片的学生通过点击浏览布顿我已经 包括在我的界面图片上传,呈现出形式

我的意思是,当我那个按钮点击一个JFileChooser弹出该过滤器只图像(我有acomplished本)

  1. 我需要的是当我在“附加按钮点击“JFilechooser,我想要图像我选择将其附加到我正在使用的表单上的jtextArea,并将JFilechooser关闭。
  2. 另外我怎么能与图像一起保存这种形式的数据库表

是否有一个地方,我可以找到有关

回答

2
JFileChooser    chooser; 
FileNameExtensionFilter  filter; 
chooser = new JFileChooser(); 
filter = new FileNameExtensionFilter("jpeg, gif and png files", "jpg", "gif", "png"); 
chooser.addChoosableFileFilter(filter); 
jButton1.addActionListener(this); 
if(e.getSource()==jButton1) 
    { 
     int i = chooser.showOpenDialog(jPanel1); 
     if(i==JFileChooser.APPROVE_OPTION) 
     { 
      jPanel2.removeAll(); 
      jPanel2.repaint(); 
      File image = chooser.getSelectedFile(); 
      ImageIcon photo = new ImageIcon(image.getAbsolutePath());    
      //jPanel2.add(new JLabel(photo)); 
      JLabel label=new JLabel("",photo,JLabel.CENTER); 
      jPanel2.add(label,BorderLayout.CENTER); 
      jPanel2.repaint();// sets a default image in image field. 
      jPanel2.revalidate(); 
     } 
    } 

注有很好的指导/教程:你应该为jpanel2 设置borderlayout,并且所选图像大小必须是jpanel2的大小