-1
I developed a Java chat using sockets where you have to choose a profile photo after logging in.
My question is: How would I save this photo chosen by the user and reuse it in a future login? In the same way that is Facebook when you put a photo, it appears there again in profile.
The code I put below is to take the photo, it takes the image and plays on 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();
}
}
}
});
Could you explain exactly where you are having a problem? Besides, how your code relates to your doubt?
– Math
Sorry for my lack of attention I edited the question, and I appreciate any help.
– jonathan
Hi, Jonathan, welcome to [en.so]. The site works differently from forums and social networks, the [Tour] is quick and explains well. I gave a simplified in your text to get straight to the point.
– brasofilo
This question cannot be answered because the code provided has little relation to the given problem. The code just loads an image onto the disk and shows on the screen, and this has little to do with sockets. Furthermore, this question is abandoned, it has already been closed and reopened and I was already going to vote to close again.
– Victor Stafusa