SlideShare a Scribd company logo
1 of 11
Download to read offline
package net.codejava.swing.mail;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Properties;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import net.codejava.swing.JFilePicker;
/**
* A Swing application that allows sending e-mail messages from a SMTP server.
* @author www.codejava.net
*
*/
public class SwingEmailSender extends JFrame {
private ConfigUtility configUtil = new ConfigUtility();
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu("File");
private JMenuItem menuItemSetting = new JMenuItem("Settings..");
private JLabel labelTo = new JLabel("To: ");
private JLabel labelSubject = new JLabel("Subject: ");
private JTextField fieldTo = new JTextField(30);
private JTextField fieldSubject = new JTextField(30);
private JButton buttonSend = new JButton("SEND");
private JFilePicker filePicker = new JFilePicker("Attached", "Attach File...");
private JTextArea textAreaMessage = new JTextArea(10, 30);
private GridBagConstraints constraints = new GridBagConstraints();
public SwingEmailSender() {
super("Swing E-mail Sender Program");
// set up layout
setLayout(new GridBagLayout());
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(5, 5, 5, 5);
setupMenu();
setupForm();
pack();
setLocationRelativeTo(null); // center on screen
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void setupMenu() {
menuItemSetting.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
SettingsDialog dialog = new SettingsDialog(SwingEmailSender.this, configUtil);
dialog.setVisible(true);
}
});
menuFile.add(menuItemSetting);
menuBar.add(menuFile);
setJMenuBar(menuBar);
}
private void setupForm() {
constraints.gridx = 0;
constraints.gridy = 0;
add(labelTo, constraints);
constraints.gridx = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
add(fieldTo, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
add(labelSubject, constraints);
constraints.gridx = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
add(fieldSubject, constraints);
constraints.gridx = 2;
constraints.gridy = 0;
constraints.gridheight = 2;
constraints.fill = GridBagConstraints.BOTH;
buttonSend.setFont(new Font("Arial", Font.BOLD, 16));
add(buttonSend, constraints);
buttonSend.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
buttonSendActionPerformed(event);
}
});
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridheight = 1;
constraints.gridwidth = 3;
filePicker.setMode(JFilePicker.MODE_OPEN);
add(filePicker, constraints);
constraints.gridy = 3;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
add(new JScrollPane(textAreaMessage), constraints);
}
private void buttonSendActionPerformed(ActionEvent event) {
if (!validateFields()) {
return;
}
String toAddress = fieldTo.getText();
String subject = fieldSubject.getText();
String message = textAreaMessage.getText();
File[] attachFiles = null;
if (!filePicker.getSelectedFilePath().equals("")) {
File selectedFile = new File(filePicker.getSelectedFilePath());
attachFiles = new File[] {selectedFile};
}
try {
Properties smtpProperties = configUtil.loadProperties();
EmailUtility.sendEmail(smtpProperties, toAddress, subject, message, attachFiles);
JOptionPane.showMessageDialog(this,
"The e-mail has been sent successfully!");
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Error while sending the e-mail: " + ex.getMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
}
}
private boolean validateFields() {
if (fieldTo.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter To address!",
"Error", JOptionPane.ERROR_MESSAGE);
fieldTo.requestFocus();
return false;
}
if (fieldSubject.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter subject!",
"Error", JOptionPane.ERROR_MESSAGE);
fieldSubject.requestFocus();
return false;
}
if (textAreaMessage.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter message!",
"Error", JOptionPane.ERROR_MESSAGE);
textAreaMessage.requestFocus();
return false;
}
return true;
}
public static void main(String[] args) {
// set look and feel to system dependent
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
ex.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingEmailSender().setVisible(true);
}
});
}
}
Solution
package net.codejava.swing.mail;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Properties;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import net.codejava.swing.JFilePicker;
/**
* A Swing application that allows sending e-mail messages from a SMTP server.
* @author www.codejava.net
*
*/
public class SwingEmailSender extends JFrame {
private ConfigUtility configUtil = new ConfigUtility();
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu("File");
private JMenuItem menuItemSetting = new JMenuItem("Settings..");
private JLabel labelTo = new JLabel("To: ");
private JLabel labelSubject = new JLabel("Subject: ");
private JTextField fieldTo = new JTextField(30);
private JTextField fieldSubject = new JTextField(30);
private JButton buttonSend = new JButton("SEND");
private JFilePicker filePicker = new JFilePicker("Attached", "Attach File...");
private JTextArea textAreaMessage = new JTextArea(10, 30);
private GridBagConstraints constraints = new GridBagConstraints();
public SwingEmailSender() {
super("Swing E-mail Sender Program");
// set up layout
setLayout(new GridBagLayout());
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(5, 5, 5, 5);
setupMenu();
setupForm();
pack();
setLocationRelativeTo(null); // center on screen
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void setupMenu() {
menuItemSetting.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
SettingsDialog dialog = new SettingsDialog(SwingEmailSender.this, configUtil);
dialog.setVisible(true);
}
});
menuFile.add(menuItemSetting);
menuBar.add(menuFile);
setJMenuBar(menuBar);
}
private void setupForm() {
constraints.gridx = 0;
constraints.gridy = 0;
add(labelTo, constraints);
constraints.gridx = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
add(fieldTo, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
add(labelSubject, constraints);
constraints.gridx = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
add(fieldSubject, constraints);
constraints.gridx = 2;
constraints.gridy = 0;
constraints.gridheight = 2;
constraints.fill = GridBagConstraints.BOTH;
buttonSend.setFont(new Font("Arial", Font.BOLD, 16));
add(buttonSend, constraints);
buttonSend.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
buttonSendActionPerformed(event);
}
});
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridheight = 1;
constraints.gridwidth = 3;
filePicker.setMode(JFilePicker.MODE_OPEN);
add(filePicker, constraints);
constraints.gridy = 3;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
add(new JScrollPane(textAreaMessage), constraints);
}
private void buttonSendActionPerformed(ActionEvent event) {
if (!validateFields()) {
return;
}
String toAddress = fieldTo.getText();
String subject = fieldSubject.getText();
String message = textAreaMessage.getText();
File[] attachFiles = null;
if (!filePicker.getSelectedFilePath().equals("")) {
File selectedFile = new File(filePicker.getSelectedFilePath());
attachFiles = new File[] {selectedFile};
}
try {
Properties smtpProperties = configUtil.loadProperties();
EmailUtility.sendEmail(smtpProperties, toAddress, subject, message, attachFiles);
JOptionPane.showMessageDialog(this,
"The e-mail has been sent successfully!");
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Error while sending the e-mail: " + ex.getMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
}
}
private boolean validateFields() {
if (fieldTo.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter To address!",
"Error", JOptionPane.ERROR_MESSAGE);
fieldTo.requestFocus();
return false;
}
if (fieldSubject.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter subject!",
"Error", JOptionPane.ERROR_MESSAGE);
fieldSubject.requestFocus();
return false;
}
if (textAreaMessage.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter message!",
"Error", JOptionPane.ERROR_MESSAGE);
textAreaMessage.requestFocus();
return false;
}
return true;
}
public static void main(String[] args) {
// set look and feel to system dependent
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
ex.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingEmailSender().setVisible(true);
}
});
}
}

More Related Content

Similar to package net.codejava.swing.mail;import java.awt.Font;import java.pdf

Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfarvindarora20042013
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonEric Wendelin
 
Groovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonGroovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonMatthew McCullough
 
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdfmohammedfootwear
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfflashfashioncasualwe
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2Pat Cavit
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdffashionfolionr
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3martha leon
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql JOYITAKUNDU1
 
Ejemplo radio
Ejemplo radioEjemplo radio
Ejemplo radiolupe ga
 
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdfInclude- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdfRyanF2PLeev
 

Similar to package net.codejava.swing.mail;import java.awt.Font;import java.pdf (20)

Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdf
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with Griffon
 
Groovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonGroovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With Griffon
 
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
 
Easy Button
Easy ButtonEasy Button
Easy Button
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
New text document
New text documentNew text document
New text document
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
Notepad
NotepadNotepad
Notepad
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Ejemplo radio
Ejemplo radioEjemplo radio
Ejemplo radio
 
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdfInclude- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
 

More from sudhirchourasia86

W since less electrons means difficult to melt so.pdf
                     W since less electrons means difficult to melt so.pdf                     W since less electrons means difficult to melt so.pdf
W since less electrons means difficult to melt so.pdfsudhirchourasia86
 
To the left. The ketone is more stable compared .pdf
                     To the left.  The ketone is more stable compared .pdf                     To the left.  The ketone is more stable compared .pdf
To the left. The ketone is more stable compared .pdfsudhirchourasia86
 
The true statement is D. Concentration affects .pdf
                     The true statement is  D. Concentration affects .pdf                     The true statement is  D. Concentration affects .pdf
The true statement is D. Concentration affects .pdfsudhirchourasia86
 
Smaller mass gases have greater rates of effusion.pdf
                     Smaller mass gases have greater rates of effusion.pdf                     Smaller mass gases have greater rates of effusion.pdf
Smaller mass gases have greater rates of effusion.pdfsudhirchourasia86
 
please send the question details I have gone thr.pdf
                     please send the question details  I have gone thr.pdf                     please send the question details  I have gone thr.pdf
please send the question details I have gone thr.pdfsudhirchourasia86
 
melting point of the compound increases due to th.pdf
                     melting point of the compound increases due to th.pdf                     melting point of the compound increases due to th.pdf
melting point of the compound increases due to th.pdfsudhirchourasia86
 
molality = moles of solute kg of solvent In thi.pdf
                     molality = moles of solute  kg of solvent In thi.pdf                     molality = moles of solute  kg of solvent In thi.pdf
molality = moles of solute kg of solvent In thi.pdfsudhirchourasia86
 
Ionic Equation is MgO(s) + 2 H+(aq) + 2NO3- (aq.pdf
                     Ionic Equation is   MgO(s) + 2 H+(aq) + 2NO3- (aq.pdf                     Ionic Equation is   MgO(s) + 2 H+(aq) + 2NO3- (aq.pdf
Ionic Equation is MgO(s) + 2 H+(aq) + 2NO3- (aq.pdfsudhirchourasia86
 
FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdf
                     FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdf                     FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdf
FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdfsudhirchourasia86
 
d) in real gases there are attraction between m.pdf
                     d)   in real gases there are attraction between m.pdf                     d)   in real gases there are attraction between m.pdf
d) in real gases there are attraction between m.pdfsudhirchourasia86
 
SolutionTraversing Binary Trees The preorder standard procedure.pdf
SolutionTraversing Binary Trees The preorder standard procedure.pdfSolutionTraversing Binary Trees The preorder standard procedure.pdf
SolutionTraversing Binary Trees The preorder standard procedure.pdfsudhirchourasia86
 
Shareholder’s equity= Current assets+Net fixed assets-Current lia.pdf
Shareholder’s equity= Current assets+Net fixed assets-Current lia.pdfShareholder’s equity= Current assets+Net fixed assets-Current lia.pdf
Shareholder’s equity= Current assets+Net fixed assets-Current lia.pdfsudhirchourasia86
 
in Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdf
in Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdfin Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdf
in Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdfsudhirchourasia86
 
   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdf
   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdf   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdf
   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdfsudhirchourasia86
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdfsudhirchourasia86
 
Initial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdf
Initial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdfInitial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdf
Initial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdfsudhirchourasia86
 
There are ten guidelines with a broad coverage, ranging from develop.pdf
There are ten guidelines with a broad coverage, ranging from develop.pdfThere are ten guidelines with a broad coverage, ranging from develop.pdf
There are ten guidelines with a broad coverage, ranging from develop.pdfsudhirchourasia86
 
The way Ive been told to look at the classifications is to look at.pdf
The way Ive been told to look at the classifications is to look at.pdfThe way Ive been told to look at the classifications is to look at.pdf
The way Ive been told to look at the classifications is to look at.pdfsudhirchourasia86
 

More from sudhirchourasia86 (20)

W since less electrons means difficult to melt so.pdf
                     W since less electrons means difficult to melt so.pdf                     W since less electrons means difficult to melt so.pdf
W since less electrons means difficult to melt so.pdf
 
To the left. The ketone is more stable compared .pdf
                     To the left.  The ketone is more stable compared .pdf                     To the left.  The ketone is more stable compared .pdf
To the left. The ketone is more stable compared .pdf
 
The true statement is D. Concentration affects .pdf
                     The true statement is  D. Concentration affects .pdf                     The true statement is  D. Concentration affects .pdf
The true statement is D. Concentration affects .pdf
 
Smaller mass gases have greater rates of effusion.pdf
                     Smaller mass gases have greater rates of effusion.pdf                     Smaller mass gases have greater rates of effusion.pdf
Smaller mass gases have greater rates of effusion.pdf
 
please send the question details I have gone thr.pdf
                     please send the question details  I have gone thr.pdf                     please send the question details  I have gone thr.pdf
please send the question details I have gone thr.pdf
 
O3, SO3, SO2 .pdf
                     O3, SO3, SO2                                     .pdf                     O3, SO3, SO2                                     .pdf
O3, SO3, SO2 .pdf
 
melting point of the compound increases due to th.pdf
                     melting point of the compound increases due to th.pdf                     melting point of the compound increases due to th.pdf
melting point of the compound increases due to th.pdf
 
molality = moles of solute kg of solvent In thi.pdf
                     molality = moles of solute  kg of solvent In thi.pdf                     molality = moles of solute  kg of solvent In thi.pdf
molality = moles of solute kg of solvent In thi.pdf
 
Ionic Equation is MgO(s) + 2 H+(aq) + 2NO3- (aq.pdf
                     Ionic Equation is   MgO(s) + 2 H+(aq) + 2NO3- (aq.pdf                     Ionic Equation is   MgO(s) + 2 H+(aq) + 2NO3- (aq.pdf
Ionic Equation is MgO(s) + 2 H+(aq) + 2NO3- (aq.pdf
 
FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdf
                     FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdf                     FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdf
FeBrs is a typo Lets suppose it is FeBr2. 2Na .pdf
 
Density increases .pdf
                     Density increases                                .pdf                     Density increases                                .pdf
Density increases .pdf
 
d) in real gases there are attraction between m.pdf
                     d)   in real gases there are attraction between m.pdf                     d)   in real gases there are attraction between m.pdf
d) in real gases there are attraction between m.pdf
 
SolutionTraversing Binary Trees The preorder standard procedure.pdf
SolutionTraversing Binary Trees The preorder standard procedure.pdfSolutionTraversing Binary Trees The preorder standard procedure.pdf
SolutionTraversing Binary Trees The preorder standard procedure.pdf
 
Shareholder’s equity= Current assets+Net fixed assets-Current lia.pdf
Shareholder’s equity= Current assets+Net fixed assets-Current lia.pdfShareholder’s equity= Current assets+Net fixed assets-Current lia.pdf
Shareholder’s equity= Current assets+Net fixed assets-Current lia.pdf
 
in Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdf
in Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdfin Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdf
in Reproductive cloning of mammals the Nucelus ( Genetic material) f.pdf
 
   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdf
   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdf   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdf
   a) OH- (aq) is a Lewis base because it can give electrions to Oth.pdf
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
 
Initial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdf
Initial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdfInitial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdf
Initial concentration of NH3 = molesvolume = 0.2501.00 = 0.250 M.pdf
 
There are ten guidelines with a broad coverage, ranging from develop.pdf
There are ten guidelines with a broad coverage, ranging from develop.pdfThere are ten guidelines with a broad coverage, ranging from develop.pdf
There are ten guidelines with a broad coverage, ranging from develop.pdf
 
The way Ive been told to look at the classifications is to look at.pdf
The way Ive been told to look at the classifications is to look at.pdfThe way Ive been told to look at the classifications is to look at.pdf
The way Ive been told to look at the classifications is to look at.pdf
 

Recently uploaded

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

package net.codejava.swing.mail;import java.awt.Font;import java.pdf

  • 1. package net.codejava.swing.mail; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.util.Properties; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.UIManager; import net.codejava.swing.JFilePicker; /** * A Swing application that allows sending e-mail messages from a SMTP server. * @author www.codejava.net * */ public class SwingEmailSender extends JFrame { private ConfigUtility configUtil = new ConfigUtility(); private JMenuBar menuBar = new JMenuBar(); private JMenu menuFile = new JMenu("File"); private JMenuItem menuItemSetting = new JMenuItem("Settings.."); private JLabel labelTo = new JLabel("To: ");
  • 2. private JLabel labelSubject = new JLabel("Subject: "); private JTextField fieldTo = new JTextField(30); private JTextField fieldSubject = new JTextField(30); private JButton buttonSend = new JButton("SEND"); private JFilePicker filePicker = new JFilePicker("Attached", "Attach File..."); private JTextArea textAreaMessage = new JTextArea(10, 30); private GridBagConstraints constraints = new GridBagConstraints(); public SwingEmailSender() { super("Swing E-mail Sender Program"); // set up layout setLayout(new GridBagLayout()); constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(5, 5, 5, 5); setupMenu(); setupForm(); pack(); setLocationRelativeTo(null); // center on screen setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setupMenu() { menuItemSetting.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { SettingsDialog dialog = new SettingsDialog(SwingEmailSender.this, configUtil); dialog.setVisible(true); } });
  • 3. menuFile.add(menuItemSetting); menuBar.add(menuFile); setJMenuBar(menuBar); } private void setupForm() { constraints.gridx = 0; constraints.gridy = 0; add(labelTo, constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; add(fieldTo, constraints); constraints.gridx = 0; constraints.gridy = 1; add(labelSubject, constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; add(fieldSubject, constraints); constraints.gridx = 2; constraints.gridy = 0; constraints.gridheight = 2; constraints.fill = GridBagConstraints.BOTH; buttonSend.setFont(new Font("Arial", Font.BOLD, 16)); add(buttonSend, constraints); buttonSend.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { buttonSendActionPerformed(event); } });
  • 4. constraints.gridx = 0; constraints.gridy = 2; constraints.gridheight = 1; constraints.gridwidth = 3; filePicker.setMode(JFilePicker.MODE_OPEN); add(filePicker, constraints); constraints.gridy = 3; constraints.weightx = 1.0; constraints.weighty = 1.0; add(new JScrollPane(textAreaMessage), constraints); } private void buttonSendActionPerformed(ActionEvent event) { if (!validateFields()) { return; } String toAddress = fieldTo.getText(); String subject = fieldSubject.getText(); String message = textAreaMessage.getText(); File[] attachFiles = null; if (!filePicker.getSelectedFilePath().equals("")) { File selectedFile = new File(filePicker.getSelectedFilePath()); attachFiles = new File[] {selectedFile}; } try { Properties smtpProperties = configUtil.loadProperties(); EmailUtility.sendEmail(smtpProperties, toAddress, subject, message, attachFiles); JOptionPane.showMessageDialog(this,
  • 5. "The e-mail has been sent successfully!"); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error while sending the e-mail: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } private boolean validateFields() { if (fieldTo.getText().equals("")) { JOptionPane.showMessageDialog(this, "Please enter To address!", "Error", JOptionPane.ERROR_MESSAGE); fieldTo.requestFocus(); return false; } if (fieldSubject.getText().equals("")) { JOptionPane.showMessageDialog(this, "Please enter subject!", "Error", JOptionPane.ERROR_MESSAGE); fieldSubject.requestFocus(); return false; } if (textAreaMessage.getText().equals("")) { JOptionPane.showMessageDialog(this, "Please enter message!", "Error", JOptionPane.ERROR_MESSAGE); textAreaMessage.requestFocus(); return false; } return true; }
  • 6. public static void main(String[] args) { // set look and feel to system dependent try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { ex.printStackTrace(); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new SwingEmailSender().setVisible(true); } }); } } Solution package net.codejava.swing.mail; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.util.Properties; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane;
  • 7. import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.UIManager; import net.codejava.swing.JFilePicker; /** * A Swing application that allows sending e-mail messages from a SMTP server. * @author www.codejava.net * */ public class SwingEmailSender extends JFrame { private ConfigUtility configUtil = new ConfigUtility(); private JMenuBar menuBar = new JMenuBar(); private JMenu menuFile = new JMenu("File"); private JMenuItem menuItemSetting = new JMenuItem("Settings.."); private JLabel labelTo = new JLabel("To: "); private JLabel labelSubject = new JLabel("Subject: "); private JTextField fieldTo = new JTextField(30); private JTextField fieldSubject = new JTextField(30); private JButton buttonSend = new JButton("SEND"); private JFilePicker filePicker = new JFilePicker("Attached", "Attach File..."); private JTextArea textAreaMessage = new JTextArea(10, 30); private GridBagConstraints constraints = new GridBagConstraints(); public SwingEmailSender() { super("Swing E-mail Sender Program"); // set up layout
  • 8. setLayout(new GridBagLayout()); constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(5, 5, 5, 5); setupMenu(); setupForm(); pack(); setLocationRelativeTo(null); // center on screen setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setupMenu() { menuItemSetting.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { SettingsDialog dialog = new SettingsDialog(SwingEmailSender.this, configUtil); dialog.setVisible(true); } }); menuFile.add(menuItemSetting); menuBar.add(menuFile); setJMenuBar(menuBar); } private void setupForm() { constraints.gridx = 0; constraints.gridy = 0; add(labelTo, constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; add(fieldTo, constraints); constraints.gridx = 0; constraints.gridy = 1;
  • 9. add(labelSubject, constraints); constraints.gridx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; add(fieldSubject, constraints); constraints.gridx = 2; constraints.gridy = 0; constraints.gridheight = 2; constraints.fill = GridBagConstraints.BOTH; buttonSend.setFont(new Font("Arial", Font.BOLD, 16)); add(buttonSend, constraints); buttonSend.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { buttonSendActionPerformed(event); } }); constraints.gridx = 0; constraints.gridy = 2; constraints.gridheight = 1; constraints.gridwidth = 3; filePicker.setMode(JFilePicker.MODE_OPEN); add(filePicker, constraints); constraints.gridy = 3; constraints.weightx = 1.0; constraints.weighty = 1.0; add(new JScrollPane(textAreaMessage), constraints); } private void buttonSendActionPerformed(ActionEvent event) { if (!validateFields()) {
  • 10. return; } String toAddress = fieldTo.getText(); String subject = fieldSubject.getText(); String message = textAreaMessage.getText(); File[] attachFiles = null; if (!filePicker.getSelectedFilePath().equals("")) { File selectedFile = new File(filePicker.getSelectedFilePath()); attachFiles = new File[] {selectedFile}; } try { Properties smtpProperties = configUtil.loadProperties(); EmailUtility.sendEmail(smtpProperties, toAddress, subject, message, attachFiles); JOptionPane.showMessageDialog(this, "The e-mail has been sent successfully!"); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error while sending the e-mail: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } private boolean validateFields() { if (fieldTo.getText().equals("")) { JOptionPane.showMessageDialog(this, "Please enter To address!", "Error", JOptionPane.ERROR_MESSAGE); fieldTo.requestFocus(); return false; }
  • 11. if (fieldSubject.getText().equals("")) { JOptionPane.showMessageDialog(this, "Please enter subject!", "Error", JOptionPane.ERROR_MESSAGE); fieldSubject.requestFocus(); return false; } if (textAreaMessage.getText().equals("")) { JOptionPane.showMessageDialog(this, "Please enter message!", "Error", JOptionPane.ERROR_MESSAGE); textAreaMessage.requestFocus(); return false; } return true; } public static void main(String[] args) { // set look and feel to system dependent try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { ex.printStackTrace(); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new SwingEmailSender().setVisible(true); } }); } }