Correio Eletronico

[Quote] hum implemente Agente Usuà ¡rio de Correio Que envia e-mail Para outros USUÁRIOS. Sua Tarefa É Programar uma interação SMTP Entre o MUA (Mail User Agent) EO Servidor SMTP local. O Cliente provar Uma interface gráfica de usuario, uma Conter qua DEVE campos endereços OS parágrafo do Remetente e destinatário fazer, o parágrafo da Mensagem Assunto e Mensagem n um Propriá. A interface de usuario DEVE Ser parecida com: gostaria de saber se esse mês de Programa ESTA De acordo com o Pedido Que foi?

package trabalho2;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Janela extends JFrame implements ActionListener, KeyListener {

public JTextField texto1 = this.addJTextField(48, 35, 661, 25);
public JTextField texto2 = this.addJTextField(48, 60, 661, 25);
public JTextField texto3 = this.addJTextField(62, 85, 646, 25);

JTextArea a = this.addJTextArea(10, 130, 700, 350);

public JTextField getT1(){
	return texto1;
}

public JTextField getT2() {
	return texto2;
}

public JTextField getT3() {
	return texto3;
}



public JTextArea getA() {
	return a;
}

public Janela(){
	
	this.setLayout(null);
	this.setResizable(false);
	this.setBounds(0, 0, 800, 600);
	this.setTitle("E-mail Eletronico");
	
	Dimension resolucao = Toolkit.getDefaultToolkit().getScreenSize();				
	this.setSize(750, 600); 														
	this.setLocation(((resolucao.width - 750) / 2),((resolucao.height - 600) / 2));	
	
	
	this.addJLabel("De:", 10, 40, 100, 10);
	this.addJLabel("Para:", 10, 65, 100, 10);
	this.addJLabel("Assunto:", 10, 90, 100, 10);
	this.addJLabel("Mensagem:", 10, 115, 100, 10);
	
	this.addJButton("Enviar", 75, 520, 193, 40);
	this.addJButton("Limpar", 288, 520, 193, 40);
	this.addJButton("Fechar", 501, 520, 193, 40);
	
	this.setVisible(true);
}

public JFrame addJFrame(String texto, int x, int y, int w, int h){
	JFrame f = new JFrame(texto);
	f.setBounds(x, y, w, h);
	this.setLayout(null);
	this.setVisible(true);
	return f;
}

public JTextField addJTextField(int x, int y, int w, int h){
	JTextField t = new JTextField();
	t.setBounds(x, y, w, h);
	t.addKeyListener(this);
	this.add(t);
	return t;
}

public JLabel addJLabel(String texto, int x, int y, int w, int h){
	JLabel l = new JLabel(texto);
	l.setBounds(x, y, w, h);
	this.add(l);
	return l;
}

public JButton addJButton(String texto, int x, int y, int w, int h){
	JButton b = new JButton(texto);
	b.setBounds(x, y, w, h);
	b.addActionListener(this);
	this.add(b);
	return b;
}

public JTextArea addJTextArea(int x, int y, int w, int h){
	JTextArea a = new JTextArea();
	a.setBounds(x, y, w, h);
	a.addKeyListener(this);
	this.add(a);
	return a;
}

public void addAlerta(){
	
	Dimension resolucao = Toolkit.getDefaultToolkit().getScreenSize();	
	JFrame f = addJFrame(" E-mail Eletronico",
			((resolucao.width - 400) / 2), ((resolucao.height - 150) / 2), 400, 150);
	f.setResizable(false);
	f.setLayout(null);
	f.setVisible(true);
	
	JButton ok = addJButton("Ok", 150, 60, 100, 30);
	f.add(ok);
	
	JLabel l = addJLabel("Mensagem enviada com sucesso!", 100, 20, 400, 30);
	f.add(l);
}

public void Enviar(){
	System.out.println(a.getText());
	System.out.println();
	addAlerta();
	// . . .
}

public void Limpar(){
	a.setText("");
}

public void Fechar(){
	System.exit(0);
}

public static void main(String[] args) {
	new Janela();
}

public void keyPressed(KeyEvent e) {
}

public void keyReleased(KeyEvent e) {
}

public void keyTyped(KeyEvent e) {
}



    public void actionPerformed(ActionEvent e) {
	JButton botao = (JButton) e.getSource();
	if(botao.getText().equals("Fechar"))
		Fechar();
	if(botao.getText().equals("Limpar"))
		Limpar();
	if(botao.getText().equals("Enviar"))
		Enviar();
	if(botao.getText().equals("Ok"))
		Fechar();
	
	class UDPCliente {

	    public UDPCliente(){}

	    public void EnviarText(String texto, String ipDestino) throws SocketException, UnknownHostException, IOException {
	        // declara socket cliente
	        DatagramSocket clienteSocket = new DatagramSocket();

	        // obtem endereço IP do servidor com o DNS
	        InetAddress endereco = InetAddress.getByName(ipDestino);

	        // ler  os dados enviados da visao
	        byte[] dadosParaEnvio = new byte[1024];
	        dadosParaEnvio = texto.getBytes();

	        // cria pacote com o dado, o endereço do server e porta do servidor
	        DatagramPacket datPacketSend = new DatagramPacket(dadosParaEnvio, dadosParaEnvio.length, endereco, 9876);

	        //envia o pacote
	        clienteSocket.send(datPacketSend);
	        clienteSocket.close();
	    }
	}
    }

}