Results 1 to 1 of 1
  1. #1
    d4nvjpl0ng4n is offline Member
    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    Default The Jframe is disable after "return;" in public void actionPerformed(ActionEvent e)

    I have two problem:

    1/ If the file does not exist in Client...It will show a Windows to notify...but when I close the notification, I can do anything else...

    2/When I click the button Upload and if there is one file existed on Server and I choose "No" overwrite...the button Upload is always at pressed state and the windows is not responding... as the following images:
    The Jframe is disable after "return;" in public void actionPerformed(ActionEvent e)-1891086_208342529362410_1613434016_n.jpg
    The Jframe is disable after "return;" in public void actionPerformed(ActionEvent e)-75967_208342526029077_1295194456_n.jpg
    The Jframe is disable after "return;" in public void actionPerformed(ActionEvent e)-1901799_208342522695744_591435243_n.jpg
    I think the problem is in return; but I don't know how to fix it.
    The code in Client
    Java Code:
    ub.addActionListener(new ActionListener() {			
    		public void actionPerformed(ActionEvent e)
    		 {											
    				try
    				{				
    					File dir=new File(dirn);
    					if(!dir.exists())
    					   {
    					    dir.mkdir();
    					   }
    					  dout.writeInt(1);				  
    					  //bw.write("UPLOAD");
    					  //bw.flush();
    					  String filename;
    					  filename=txt.getText();
    					  
    					  File f=new File(dirn + filename);
    						if(!f.exists())
    						{
    							JOptionPane.showMessageDialog(null,"File not Exists","Message Dialog Demo",JOptionPane.INFORMATION_MESSAGE);
    							//System.out.println("File not Exists...");
    							pw.println("File not found");
    							return;
    							
    						}
    					  pw.println(filename);
    					  
    					  String msgFromServer=br.readLine();
    					  if(msgFromServer.compareTo("File Already Exists")==0)
    						{								
    							int i = JOptionPane.showConfirmDialog(null,"File Already Exists. Want to OverWrite (Y/N) ?","Comfirm Dialog",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);				
    							if(i==0)	
    							{
    								pw.println("Y");
    								
    							}
    							else
    							{
    								pw.println("N");
    								
    								return;																
    							}
    						}
    					  System.out.println("Sending File ...");
    					  FileInputStream fin=new FileInputStream(f);
    						int ch;
    						do
    						{
    							ch=fin.read();
    							pw.println(String.valueOf(ch));
    						}
    						while(ch!=-1);
    						fin.close();				   
    					   JOptionPane.showMessageDialog(null,br.readLine(),"Message Dialog Demo",JOptionPane.INFORMATION_MESSAGE);
    					   
    				}
    				catch(Exception ex)
    				{
    					System.out.println(ex.getMessage());
    				}					
    			}
    			
    		 
    		});
    Code in Server
    Java Code:
    public void run()
    	{
    		try
    		{
    			bw = new BufferedWriter(new OutputStreamWriter(soc.getOutputStream()));
    			pw = new PrintWriter(soc.getOutputStream(), true);
    			reader = new InputStreamReader(soc.getInputStream());
    			br = new BufferedReader(reader);
    			din=new DataInputStream(soc.getInputStream());
    			dout=new DataOutputStream(soc.getOutputStream());
    			out= soc.getOutputStream();
    			//////
    			//Check command
    			
    			File dir=new File(dirn);
                if(!dir.exists())
                {
                 dir.mkdir();
                }	
                while(true)
                {            
                int z = din.readInt();
                
                System.out.println(z);
    			if(z==1)
    			{
    				String filename = br.readLine();	
    				System.out.println(filename);
    				if(filename.compareTo("File not found")==0)
    				{				
    					return;
    				}
    				              
    				File f = new File(dir,filename);
    				String option;
    				if(f.exists())
    				{
    					pw.println("File Already Exists");
    					option= br.readLine();
    				}
    				else
    				{
    					pw.println("SendFile");
    					option="Y";					
    				}
    					
    					if(option.compareTo("Y")==0)
    					{
    						FileOutputStream fout=new FileOutputStream(f);
    						int ch;
    						String temp;
    						do
    						{
    							temp=br.readLine();
    							ch=Integer.parseInt(temp);
    							if(ch!=-1)
    							{
    								fout.write(ch);					
    							}
    						}while(ch!=-1);
    						fout.close();
    						pw.println("File Send Successfully");
    					}
    					else
    					{												
    						return;
    					}
    
    			  }
    			
                }            
    		}
    		catch (Exception ecc)
    		{
    			System.out.println(ecc.getMessage());
    		}
    		
    		
    	}
    Last edited by d4nvjpl0ng4n; 02-20-2014 at 11:55 PM.

Similar Threads

  1. Simple question about "actionPerformed"
    By Jib in forum New To Java
    Replies: 2
    Last Post: 09-29-2013, 04:27 PM
  2. Replies: 8
    Last Post: 12-14-2012, 02:34 PM
  3. Replies: 10
    Last Post: 02-19-2012, 05:14 AM
  4. How can I solve "void cannot be dereferenced" error?
    By fervent07 in forum New To Java
    Replies: 2
    Last Post: 04-05-2010, 09:54 PM
  5. Replies: 3
    Last Post: 05-21-2009, 04:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •