I developed a chat in Java using sockets where you have to choose a profile photo after login is done.
My question is: How would I save this user-chosen photo and reuse it in a future login? Just as Facebook is when you put a picture, it appears there again in the profile.
The code I put below is to take the picture, it takes the image and plays it in a JLabel:
foto.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
foto.setToolTipText("Altere sua foto.");
}
@Override
public void mouseClicked(MouseEvent e) {
e.getComponent().setCursor(
Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"png", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(getParent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
BufferedImage image = null;
try {
image = ImageIO.read(file);
foto.setIcon(new ImageIcon(image.getScaledInstance(130,
130, Image.SCALE_DEFAULT)));
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});