package d;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
//import java.security.Security;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Deneme {
	private static final String SMTP_HOST_NAME = "smtp.gmail.com";
	private static final String SMTP_PORT = "465";
	private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
	
	JButton buton;
	JButton buton1;
	JButton buton2;
	JButton buton3;
	JLabel label;
	JLabel label1;
	JLabel label2;
	JTextArea text;
	public Deneme(){
		JFrame frm = new JFrame("SeniÇokSeviyorum!");
		frm.setSize(380,300);
		frm.getContentPane().setLayout(new FlowLayout());
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		buton = new JButton("Evet");
		buton1 = new JButton("Hayır!");
		buton2 = new JButton("Düşünmem Lazım...");
		buton3 = new JButton("Yolla");
		buton3.setVisible(false);
		label = new JLabel("Seni Çok Seviyorum! Benimle Çıkar mısın ?");
		label1 = new JLabel("Bana Mesaj Yazmak İstersen Aşağıya Yazabilirsin...");
		label1.setVisible(false);
		label2 = new JLabel();
		text = new JTextArea(12,30);
		text.setEnabled(false);
		text.setBorder(BorderFactory.createLineBorder(Color.gray));
		frm.getContentPane().add(label);
		frm.getContentPane().add(buton);
		frm.getContentPane().add(buton1);
		frm.getContentPane().add(buton2);
		frm.getContentPane().add(label2);
		//frm.getContentPane().add(label1);
		//frm.getContentPane().add(text);
		//frm.getContentPane().add(buton3);
		buton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0){
				try{
			label2.setText("Oh Be :) Seni Çok Seviyorum...");
			label1.setVisible(true);
			text.setEnabled(true);
			buton3.setVisible(true);
			buton1.setEnabled(false);
			buton2.setEnabled(false);
			String sendTo = "agtasonur@gmail.com";
			String emailSubjectTxt="Evet Dedi *** :)";
			String emailMsgTxt="Hadi Yine Iyisin...";
			String emailFromAddress="external@linuxmail.org";

			// Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

			new Deneme().sendSSLMessage(sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress);
			System.out.println("Mesaj Gitti");
				}catch (Exception e) {
					// TODO: handle exception
				}
			}	});
		
		buton1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				try{
				label2.setText("Seni Yinede Çok Seviyorum. Seni Unutmucam...");
				label1.setVisible(true);
				text.setEnabled(true);
				buton3.setVisible(true);
				buton.setEnabled(false);
				buton2.setEnabled(false);
				String sendTo = "agtasonur@gmail.com";
				String emailSubjectTxt="Hayir Dedi :(";
				String emailMsgTxt="Üzülme...";
				String emailFromAddress="external@linuxmail.org";

				// Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

				new Deneme().sendSSLMessage(sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress);
				System.out.println("Mesaj Gitti");
				}catch (Exception e) {
					// TODO: handle exception
				}
			}
		});
		buton2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				try{
				label2.setText("Tamam Canım Cevabını Bekliyorum...");
				label1.setVisible(true);
				text.setEnabled(true);
				buton3.setVisible(true);	
				buton.setEnabled(false);
				buton1.setEnabled(false);
				String sendTo = "agtasonur@gmail.com";
				String emailSubjectTxt="Düşünücekmiş...";
				String emailMsgTxt="Ins Kabul Eder. Suan Düsünüyor...";
				String emailFromAddress="external@linuxmail.org";

				// Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

				new Deneme().sendSSLMessage(sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress);
				System.out.println("Mesaj Gitti");
				}catch (Exception ed) {
					// TODO: handle exception
				}
			}
		});
	frm.setVisible(true);
	}
	public static void main(String[] args){
		Deneme d = new Deneme();
	}
	
	public void sendSSLMessage(String recipients, String subject, String message, String from) throws MessagingException {
		boolean debug = true;

		Properties props = new Properties();
		props.put("mail.smtp.host", SMTP_HOST_NAME);
		props.put("mail.smtp.auth", "true");
		props.put("mail.debug", "true");
		props.put("mail.smtp.port", SMTP_PORT);
		props.put("mail.smtp.socketFactory.port", SMTP_PORT);
		props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
		props.put("mail.smtp.socketFactory.fallback", "false");

		Session session = Session.getDefaultInstance(props,
		new javax.mail.Authenticator() {

		protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication("*****", "******");
		}
		});

		session.setDebug(debug);

		Message msg = new MimeMessage(session);
		InternetAddress addressFrom = new InternetAddress(from);
		msg.setFrom(addressFrom);

		InternetAddress addressTo = new InternetAddress(recipients);
		msg.addRecipient(Message.RecipientType.TO, addressTo);

		// Setting the Subject and Content Type
		msg.setSubject(subject);
		msg.setContent(message, "text/plain");
		Transport.send(msg);
		}
	
}
kendi çapımda böyle bi program yaptım ama bi butona tıklanıldığında o pencere tekrar açılıyor.yapmak istediğim açılan pencerede işlemlerin yapılması yeni pencereye gerek yok. acaba nasıl yapabilirim bunu ?