private void sendButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sendButtonMouseClicked
        try {
            if(!jLabel2.getText().equals("Online")){
                String message = "Server is not online";
                JOptionPane.showMessageDialog(this, message);
                return;
            }
            if(jLabel3.getText().equals("No file selected!")){
                String message = "Please select a file";
                JOptionPane.showMessageDialog(this, message);
                return;
            }
            jSlider1.setEnabled(false);
            //            u.sendFile();
            
            int reply = u.request();
            if(reply == 0){
                String message = "Server rejected file transfer.";
                JOptionPane.showMessageDialog(this, message);
            } else if(reply == 1){
                int n;
                int packetsLeft;
                if(u.fileSize%u.chunkSize != 0){
                    u.numberOfPackets = u.fileSize/u.chunkSize;
                    u.numberOfPackets++;
                }
                else{
                    u.numberOfPackets = u.fileSize/u.chunkSize;
                }

                if(u.numberOfPackets%u.windowSize != 0){
                    n = u.numberOfPackets/u.windowSize;
                    n++;
                }
                else{
                    n = u.numberOfPackets/u.windowSize;
                } //n will represent the number of windows we'll have to send to transfer the whole file
                packetsLeft = u.numberOfPackets;
                int progress = 0;
                while(n > 0){
                    if(packetsLeft > u.windowSize){
                        u.createWindow(u.windowSize);
                        packetsLeft -= u.windowSize;
                    } else{
                        u.createWindow(packetsLeft);
                    }
                    progress += u.sendWindow(u.windowBuffer);
                    jLabel7.setText(Integer.toString(progress));
                    Rectangle labelRect = jLabel7.getBounds();
                    labelRect.x = 0;
                    labelRect.y = 0;
                    jLabel7.paintImmediately( labelRect );
                    jProgressBar1.setValue(progress);
                    Rectangle progressRect = jProgressBar1.getBounds();
                    progressRect.x = 0;
                    progressRect.y = 0;
                    jProgressBar1.paintImmediately( progressRect );
                    n--;
//                    try {
//                        Thread.sleep(100L);  //i forgot why I added this delay.
//                    } catch (InterruptedException ex) {
//                        Logger.getLogger(Udp.class.getName()).log(Level.SEVERE, null, ex);
//                    }
                }
            }

            jSlider1.setEnabled(true);
        } catch (IOException ex) {
            Logger.getLogger(mainJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_sendButtonMouseClicked