Ciao!
Ho creato una finestra dove è possibile scegliere un'immagine e visualizzarla in un pannello.
Però vorrei che tale immagine fosse memorizzata in un database mysql per poi poterla visualizzare in un jpanel posto in un'altra finestra. Come posso fare??
![]()
codice:package org.img.classi; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class img extends JFrame implements ActionListener { File f; JLabel img; JScrollPane sc; private ImageIcon createImageIcon(String path) { try { return new ImageIcon(path); } catch (Exception e) { System.out.println(e.toString()); return null; } } public void actionPerformed (ActionEvent ae) { try { JFileChooser fc = new JFileChooser(); fc.showDialog(this, "Scegli Foto"); f = fc.getSelectedFile(); try { img.setVisible(false); sc.setVisible(false); } catch (Exception ex) {} img = new JLabel(createImageIcon(f.getAbsolutePath())); sc = new JScrollPane(img); this.getContentPane().add(sc, BorderLayout.CENTER); this.validate(); } catch (Exception e) {} } public img() { super("Image display"); JButton open = new JButton("Scegli Foto"); this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(open, BorderLayout.NORTH); open.addActionListener(this); this.setSize(300, 300); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main (String[] args) { img d = new img(); } }

Rispondi quotando

