Every time when i try to catch exception on the rage of my port
Also the Message input box ( can't enter the negative number )
The program seems like doesn't response for my action
but when i disable all the code below it will work fine

Here is code

private void connetButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
       
    
        String servName = serverField.getText();      
        
        int servPort = Integer.valueOf(portTextField.getText());
        request = messageField.getText();
          
            
            
//        
//       try{ // Define Area of port that using
//        
//         int servPort = Integer.valueOf(portTextField.getText());
//            
//            request = messageField.getText();
//       
//            int i = Integer.parseInt(request);
//        if(i<0){
//              JOptionPane.showMessageDialog(null, "Could not Enter A Negative Integer!"); 
//        }
//        if(servPort > 10000 && servPort < 65536){
//            
//        }else{
//	JOptionPane.showMessageDialog(null, "Port Number Must Be Between 10001 to 65535");
//	}
//        
//       }
//        catch(NumberFormatException e){
//            JOptionPane.showMessageDialog(null, "Port Number Must Be Only Interger");
//        
   !!!!! This Area seem like it doesn't work for my program
 ///////////////////////////////////////////////////////////////////////////////////////////      
    
          DatagramSocket soc = null;
        
       
          
          try { // socket that is going to be send PLUS Set time out 3 sec
            soc = new DatagramSocket();
        } catch (SocketException ex) {
             JOptionPane.showMessageDialog(null, "Fill The Gap DAMMIT !");
        }
        try {
            soc.setSoTimeout(3000);
        } catch (SocketException ex) {
            JOptionPane.showMessageDialog(null,"TIME OUT!");
        }

				InetAddress IPAddress = null;
       
        try {
            IPAddress = InetAddress.getByName(servName);
        } catch (UnknownHostException ex) {
            JOptionPane.showMessageDialog(null,"Unknow Exception");
        }
				byte[] sendData = new byte[1024];
				byte[] receiveData = new byte[1024];

				sendData = request.getBytes();
                               int servPort = Integer.valueOf(portTextField.getText());// but if i put this the line below is going to work however Nothing will send to the server

	DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length, IPAddress, servPort); // This line is gonna to be red line if i catch the exception above 
        
        try {
            soc.send(sendPacket);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null,"");
        }
	
	DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            try {
                soc.receive(receivePacket);
				
            } catch (IOException ex) {
                Logger.getLogger(netInterface.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        
    }

plz give me some advice

Every time when i try to catch exception on the rage of my port
Also the Message input box ( can't enter the negative number )
The program seems like doesn't response for my action
but when i disable all the code below it will work fine

Here is code

private void connetButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
       
    
        String servName = serverField.getText();      
        
        int servPort = Integer.valueOf(portTextField.getText());
        request = messageField.getText();
          
            
            
//        
//       try{ // Define Area of port that using
//        
//         int servPort = Integer.valueOf(portTextField.getText());
//            
//            request = messageField.getText();
//       
//            int i = Integer.parseInt(request);
//        if(i<0){
//              JOptionPane.showMessageDialog(null, "Could not Enter A Negative Integer!"); 
//        }
//        if(servPort > 10000 && servPort < 65536){
//            
//        }else{
//	JOptionPane.showMessageDialog(null, "Port Number Must Be Between 10001 to 65535");
//	}
//        
//       }
//        catch(NumberFormatException e){
//            JOptionPane.showMessageDialog(null, "Port Number Must Be Only Interger");
//        
   !!!!! This Area seem like it doesn't work for my program
 ///////////////////////////////////////////////////////////////////////////////////////////      
    
          DatagramSocket soc = null;
        
       
          
          try { // socket that is going to be send PLUS Set time out 3 sec
            soc = new DatagramSocket();
        } catch (SocketException ex) {
             JOptionPane.showMessageDialog(null, "Fill The Gap DAMMIT !");
        }
        try {
            soc.setSoTimeout(3000);
        } catch (SocketException ex) {
            JOptionPane.showMessageDialog(null,"TIME OUT!");
        }

				InetAddress IPAddress = null;
       
        try {
            IPAddress = InetAddress.getByName(servName);
        } catch (UnknownHostException ex) {
            JOptionPane.showMessageDialog(null,"Unknow Exception");
        }
				byte[] sendData = new byte[1024];
				byte[] receiveData = new byte[1024];

				sendData = request.getBytes();
                               int servPort = Integer.valueOf(portTextField.getText());// but if i put this the line below is going to work however Nothing will send to the server

	DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length, IPAddress, servPort); // This line is gonna to be red line if i catch the exception above 
        
        try {
            soc.send(sendPacket);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null,"");
        }
	
	DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            try {
                soc.receive(receivePacket);
				
            } catch (IOException ex) {
                Logger.getLogger(netInterface.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        
    }

plz give me some advice

The first problem i see is here at your catch:

try {
...
}catch(NumberFormatException e){
//            JOptionPane.showMessageDialog(null, "Port Number Must Be Only Interger");

where is you closing brace '}'? like so:

try {
...
}catch(NumberFormatException e){
//            JOptionPane.showMessageDialog(null, "Port Number Must Be Only Interger");
}

if that does not help my next question is, is the program throwing an error? and if so what does it say?

Yeah you're Right

try {
    ...
}catch(NumberFormatException e){
    // JOptionPane.showMessageDialog(null, "Port Number Must Be Only Interger");
}

but after i put the close brace

DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length, IPAddress, servPort);

this line become red and then i declared int servPort; on the top agin

try {
    soc.send(sendPacket);
} catch (IOException ex) {
    JOptionPane.showMessageDialog(null,"");
}

now the exception catch this stage that i enter nothing on the field

what Exception does it throw now?

what does the exception say?
and i would suggest to add this to the top of your code int servPort = Integer.valueOf(portTextField.getText()); because right now you are declaring it twice, one in the first try statement and again down before you call DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length, IPAddress, servPort);

alright thank you sir
i just add this to the top of my code and it works now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.