NetSendGUI

[code]import javax.swing.;
import java.io.
;
import java.awt.;
import java.awt.event.
;
import java.util.;
import java.text.
;
import java.util.regex.*;

//
public class NetSendGUI extends JFrame implements ActionListener{
/
/
private JComboBox to = new JComboBox();
private JTextArea message = new JTextArea(10,30);
private JButton btnRefresh = new JButton(“Refresh”);
private JButton btnSend = new JButton(“Send”);
private JLabel lblStatus = new JLabel();

/* remove trailing whitespace */
public static String rtrim(String source) {
    return source.replaceAll("\s+$", "");
}

public void showException(Exception e){
	JOptionPane.showMessageDialog(null,e.toString());
}

/****/
public void loadTo(){
//
setTitle("NetSendGUI by HLINO");	
	
//clean
to.removeAll();
    try {
        // Execute command
        String command = "cmd /c net view";
        Process child = Runtime.getRuntime().exec(command);
    
        // Get the input stream and read from it
        InputStream in = child.getInputStream();
        int c;
        String line = new String();
        //
        while ((c = in.read()) != -1) {
        	//enter
	        if((char)c == '\n'){
        		//startsWith
        		if(line.indexOf("\") != -1){
	        		rtrim(line);
	        		line = line.replaceAll("\n","");
	        		line = line.replace("\","");
        			to.addItem(line); 
    			}
    			//
    			line = "";
        	}
        	//
            line = line + (char)c;
         }
        in.close();
    } catch (IOException e) {
	    showException(e);
    }
}

/****/
public String netSend(){
String line = new String();
	try{		
		String ip = to.getSelectedItem().toString();
        String command = "cmd /c net send " + ip + " \"" +  message.getText() +"\"";
        System.out.println(command);
        Process child = Runtime.getRuntime().exec(command);

        // Get the input stream and read from it
        InputStream in = child.getInputStream();
        int c;
        //
        while ((c = in.read()) != -1) {
        	//
            line = line + (char)c;
         }
        in.close();
        
	}catch(IOException e){
		showException(e);
	}
return line;
}

/****/
public NetSendGUI(){
	//
	setLayout( new BorderLayout() );
	//
	add(to, BorderLayout.NORTH);
	add(new JScrollPane(message), BorderLayout.CENTER);
	JPanel pSouth = new JPanel();
	pSouth.setLayout( new BorderLayout() );
	
		JPanel pButton = new JPanel();
		//
		pButton.add(btnRefresh);
		pButton.add(btnSend);
		//
		btnSend.setMnemonic('s');
		btnRefresh.setMnemonic('r');
	
	pSouth.add(lblStatus, BorderLayout.NORTH);
	pSouth.add(pButton, BorderLayout.CENTER);
		
	//
	add(pSouth, BorderLayout.SOUTH);
	//
	loadTo();
	//
	to.addActionListener(this);		
	btnRefresh.addActionListener(this);
	btnSend.addActionListener(this);
	//
	setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	//pack
	pack();
	//center
	setLocationRelativeTo(null);
	//visible
	setVisible(true);
}

/****/
public void refresh(){
	loadTo();
	this.lblStatus.setText("");
	this.to.requestFocus(true);
}

/**
  * @param message
  **/
public void setStatus(String message){
	Date d = new Date();
	SimpleDateFormat sdf = new SimpleDateFormat ("HH:mm:ss");

	this.lblStatus.setText( "[" + sdf.format( d ) + "] : " + message);
}

/**
  * @param e
  **/
public void actionPerformed(ActionEvent e){
	if(e.getSource() == to){
		message.requestFocus(true);
	}
	else if(e.getSource() == btnSend){
		String sReturn = netSend();
		setStatus(sReturn);
		message.requestFocus(true);
		
	}
	else if(e.getSource() == btnRefresh){
		refresh();
	}	
}
/**
  * @param args
  **/
public static void main(String args[]){
	//
	new NetSendGUI();
}

}[/code]

Post sem noção?

O colega de poucas palavras está compartilhando o código dele que é uma interface gráfica para o comando net send do windows. :slight_smile:

Beleza cara!

Somente como sugestão, não teria tempo de fazer um pequeno tutorial? Acho que seria interessante para quem tá começando, pois o programa tem funcionalidade real.

Parabéns.