Save user profile photo while relogging on the system of a chat using socket

-1

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();
                }
            }
        }
    });
    
asked by anonymous 20.10.2014 / 17:36

1 answer

0

Keep this information on your chat server. In a very simplistic way, you can create a directory on the machine where your chat server is (using the user id as the name of the photo, for example). Then when the user reconnects to the server, you return the byte array of the photo on the socket and mount it on the client.

    
14.11.2014 / 04:36