public class Janela extends javax.swing.JFrame {
/**
* Creates new form Janela
*/
public Janela() {
initComponents();
SetImagemFundo();
}
public void SetImagemFundo(){
Properties prop = new Properties();
try {
InputStream is = new FileInputStream("Imagens_Salvas");
prop.load(is);
String url = prop.getProperty("ID");
ImageIcon imagem = new ImageIcon(url);
lblImagem.setIcon(new ImageIcon(imagem.getImage().getScaledInstance(lblImagem.getWidth(), lblImagem.getHeight(), Image.SCALE_DEFAULT)));
} catch (FileNotFoundException ex) {
Logger.getLogger(Janela.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Janela.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser jfc = new JFileChooser();
if(jfc.showOpenDialog(null) == 0){
String url = jfc.getSelectedFile().getAbsolutePath();
txtUrl.setText(url);
ImageIcon imagem = new ImageIcon(url);
lblImagem.setIcon(new ImageIcon(imagem.getImage().getScaledInstance(lblImagem.getWidth(), lblImagem.getHeight(), Image.SCALE_DEFAULT)));
prop.setProperty("ID", url); //o id vai identificar a url que eu quero pegar
try {
FileOutputStream fos = new FileOutputStream("Imagens_Salvas");
prop.store(fos, null); // salva o documento na raiz do projeto
fos.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(Janela.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Janela.class.getName()).log(Level.SEVERE, null, ex);
}
}
}