import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.HashMap;
import javax.swing.*;
public class InvokerRx {
public static void main(String[] args) {
String windows = "com.sun.java.swing" +
".plaf.windows.WindowsLookAndFeel";
try {
UIManager.setLookAndFeel(windows);
} catch (Exception e) {
System.out.println(e.getClass().getName() + ": " +
e.getMessage());
}
new MailClientRx(null, "Mail Client", true);
}
}
class MailClientRx extends JDialog {
private JPanel mailPanel = null;
private JTextArea jtaMessage = null;
private JButton jbtSend = null;
private JButton jbtCancel = null;
private JButton jbtAttachment = null;
private JLabel jlbTo = null;
private JLabel jlbCc = null;
private JLabel jlbBcc = null;
private JLabel jlbSubject = null;
private JList jlstAttachedFiles = null;
private JScrollPane jlstAttachedFilesPane = null;
private JTextField jtfTo = null;
private JTextField jtfCc = null;
private JTextField jtfBcc = null;
private JTextField jtfSubject = null;
private JFileChooser jfcOpenChooser = null;
private JMenuBar jmenubar = null;
private JMenu jmenuFile = null;
private JMenu jmenuHelp = null;
private JMenu jmenuEdit = null;
private JMenuItem jmenuitemNew = null;
private JMenuItem jmenuitemCut = null;
private JMenuItem jmenuitemCopy = null;
private JMenuItem jmenuitemPaste = null;
private JMenuItem jmenuitemAttachments = null;
private JMenuItem jmenuitemHelp = null;
private JMenuItem jmenuitemExit = null;
private JButton jbtCut = null;
private JButton jbtCopy = null;
private JButton jbtPaste = null;
private JButton jbtHelp = null;
private JButton jbtAttachmentsTb = null;
private JToolBar jtoolbar = null;
private ImageIcon cutIcon = null;
private ImageIcon copyIcon = null;
private ImageIcon helpIcon = null;
private ImageIcon pasteIcon = null;
private ImageIcon attachmentsIcon = null;
JScrollPane mailMessage;
public MailClientRx(Frame frame, String title, boolean modal) {
super(frame, title, modal);
initComponents();
layoutComponents();
}
public MailClientRx() {
this((Frame)null, "", false);
}
private void initComponents(){
JFrame.setDefaultLookAndFeelDecorated(true);
this.setSize(400, 400);
jlbTo = new JLabel("To");
jlbCc = new JLabel("CC");
jlbBcc = new JLabel("BCC");
jlbSubject = new JLabel("Subject");
jlstAttachedFiles = new JList();
jlstAttachedFilesPane = new JScrollPane(jlstAttachedFiles);
jlstAttachedFilesPane.setPreferredSize(new Dimension(150, 75));
jbtAttachment = new JButton("Attachments");
jbtSend = new JButton("Send");
jbtCancel = new JButton("Cancel");
jtfTo = new JTextField() ;
jtfCc = new JTextField();
jtfBcc = new JTextField();
jtfSubject = new JTextField();
jtaMessage = new JTextArea();
jtaMessage.setPreferredSize(new java.awt.Dimension(300, 200));
jtaMessage.setMinimumSize(new java.awt.Dimension(100, 50));
/*JScrollPane*/ mailMessage = new JScrollPane(jtaMessage);
jtaMessage.setLineWrap(true);
jfcOpenChooser = new JFileChooser();
jtoolbar = new JToolBar();
cutIcon = new ImageIcon("cut.jpg");
copyIcon = new ImageIcon("copy.jpg");
helpIcon = new ImageIcon("help.gif");
pasteIcon = new ImageIcon("paste.jpg");
attachmentsIcon = new ImageIcon("attachments.jpg");
jmenubar = new JMenuBar();
jmenuFile = new JMenu("File");
jmenuHelp = new JMenu("Help");
jmenuEdit = new JMenu("Edit");
jmenuitemNew = new JMenuItem("New Mail");
jmenuitemCut = new JMenuItem("Cut", cutIcon);
jmenuitemCopy = new JMenuItem("Copy", copyIcon);
jmenuitemPaste = new JMenuItem("Paste", pasteIcon);
jmenuitemAttachments = new JMenuItem("Attachments", attachmentsIcon);
jmenuitemHelp = new JMenuItem("Help", helpIcon);
jmenuitemExit = new JMenuItem("Exit");
jbtCut = new JButton(cutIcon);
jbtCopy = new JButton(copyIcon);
jbtPaste = new JButton(pasteIcon);
jbtHelp = new JButton(helpIcon);
jbtAttachmentsTb = new JButton(attachmentsIcon);
jbtCut.setToolTipText("Cut");
jbtCopy.setToolTipText("Copy");
jbtPaste.setToolTipText("Paste");
jbtHelp.setToolTipText("Help");
jbtAttachmentsTb.setToolTipText("Attachment");
jmenuFile.add(jmenuitemNew);
jmenuFile.add(jmenuitemCut);
jmenuEdit.add(jmenuitemCopy);
jmenuEdit.add(jmenuitemPaste);
jmenuEdit.add(jmenuitemAttachments);
jmenuHelp.add(jmenuitemHelp);
jmenuHelp.add(jmenuitemExit);
jmenubar.add(jmenuFile);
jmenubar.add(jmenuEdit);
jmenubar.add(jmenuHelp);
jtoolbar.add(jbtCut);
jtoolbar.add(jbtCopy);
jtoolbar.add(jbtPaste);
jtoolbar.add(jbtHelp);
jtoolbar.add(jbtAttachmentsTb);
jbtSend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jbtOK_actionPerformed(e);
}
});
jbtCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jbtCancel_actionPerformed(e);
}
});
jbtAttachment.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jbtAttachment_actionPerformed(e);
}
});
}
private void layoutComponents() {
this.setLayout(new GridBagLayout());
GridBagConstraints toolbarCons = new GridBagConstraints();
toolbarCons = new GridBagConstraints(0,0,1,1,0.1,0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5,5,0,5),0,0);
mailPanel = new JPanel();
mailPanel.setLayout(new GridBagLayout());
GridBagConstraints cons = new GridBagConstraints();
cons = new GridBagConstraints(0,0,1,1,0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jlbTo, cons);
cons = new GridBagConstraints(1,0,4,1,1.0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5,5,0,5),0,0);
mailPanel.add(jtfTo, cons);
cons = new GridBagConstraints(0,1,1,1,0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jlbCc, cons);
cons = new GridBagConstraints(1,1,4,1,1.0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5,5,0,5),0,0);
mailPanel.add(jtfCc, cons);
cons = new GridBagConstraints(0,2,1,1,0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jlbBcc, cons);
cons = new GridBagConstraints(1,2,4,1,1.0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5,5,0,5),0,0);
mailPanel.add(jtfBcc, cons);
cons = new GridBagConstraints(0,3,1,1,0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jlbSubject, cons);
cons = new GridBagConstraints(1,3,4,1,1.0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5,5,0,5),0,0);
mailPanel.add(jtfSubject, cons);
cons = new GridBagConstraints(0,4,1,1,0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jbtAttachment, cons);
cons = new GridBagConstraints(1,4,1,1,1.0,1.0, // 4 col
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jlstAttachedFilesPane, cons);
cons = new GridBagConstraints(1,5,1,1,1.0,1.0, // 4c 4r
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5,5,0,5),0,0);
mailPanel.add(mailMessage, cons);
cons = new GridBagConstraints(0,9,1,1,0,0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jbtSend, cons);
cons = new GridBagConstraints(1,9,1,1,0,0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5,5,0,5),0,0);
mailPanel.add(jbtCancel, cons);
// this.getContentPane().add(mailPanel, toolbarCons);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setJMenuBar(jmenubar);
jtoolbar.setFloatable(false);
this.getContentPane().add(jtoolbar, toolbarCons);
GridBagConstraints mainPanelCons = new GridBagConstraints();
mainPanelCons = new GridBagConstraints(0,1,1,1,1.0,1.0,
GridBagConstraints.WEST,
GridBagConstraints.BOTH,
new Insets(5,5,0,5),0,0);
this.getContentPane().add(mailPanel, mainPanelCons);
this.pack();
this.setVisible(true);
}
private void jbtOK_actionPerformed(ActionEvent e) {
// Business Logic
this.dispose();
}
private void jbtCancel_actionPerformed(ActionEvent e) {
this.dispose();
}
private void jbtAttachment_actionPerformed(ActionEvent e) {
jfcOpenChooser.setMultiSelectionEnabled(true);
jfcOpenChooser.showOpenDialog(null);
File[] fileArray = jfcOpenChooser.getSelectedFiles();
String[] fileNames = new String[fileArray.length];
for(int i=0; i < fileArray.length; i++){
File file = fileArray[i];
fileNames[i] = file.getPath().trim();
// fileNames[i] = file.getName().trim();
}
jlstAttachedFiles.setListData(fileNames);
}
}