/*------------------------------------------- 3/4/2000 --------------------------------------------*/ /* ***************************************************************************** Copyright 2000 by Erica Andrews (cylikon@hotmail.com). All rights reserved. ./ButchWhipAppeal/ ./IcedPinky/ NO portion of this software may be used in ANY way by anyone other than myself without my express written consent. If it is downloaded for testing, it must be deleted from your system within 24 hours. Any other use constitutes piracy and fraudulent misuse of this software, punishable in a court of law. Copyright 2000 by Erica Andrews. All rights reserved. ***************************************************************************** */ package cylikon.EJBMail; import javax.swing.border.*; import java.net.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; import javax.ejb.*; import javax.naming.*; import java.rmi.*; public class EJBMailClient extends JFrame { public static ClientPanel cp; public EJBMailClient() { setTitle("EJBMail Client"); setBounds(new Rectangle(130,90,516,395)); setSize(466,322); setBackground(new Color(204,140,253)); cp = new ClientPanel(); getContentPane().add(cp); // pack(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { hide(); dispose(); System.exit(0); } public void windowOpened(WindowEvent e) { resize(466,322); repaint(); cp.repaint(); } } ); show(); setResizable(false); } //end super method public static void main (String args[]) { new EJBMailClient(); } } //end of class CLient // ********************MAIN PANEL************************* class ClientPanel extends JPanel { // Instance variables public JTextField jtextfield1; public JTextField jtextfield3; public JButton jbutton0; public JLabel jlabel0; public JLabel jlabel1; public TextArea textarea0; public ClientPanel() { // Setup GUI this.setBounds(10,6,458,302); this.setSize(new Dimension(458,302)); this.setPreferredSize(new Dimension(1,1)); Border thisBorder0 = new EtchedBorder(); this.setBorder(thisBorder0); this.setName("this"); this.setLocation(new Point(10,6)); this.setMinimumSize(new Dimension(1,1)); this.setToolTipText("EJBMailDaemon Client"); this.setBounds(new Rectangle(10,6,458,302)); this.setForeground(new Color(149,0,207)); this.setBackground(new Color(204,140,253)); this.setLayout(null); jtextfield1 = new JTextField(); jtextfield1.setToolTipText("Enter YOUR email address."); jtextfield1.setBounds(new Rectangle(87,16,199,21)); jtextfield1.setSize(new Dimension(199,21)); jtextfield1.setName("jtextfield1"); Border jtextfield1Border0 = new BevelBorder(1); jtextfield1.setBorder(jtextfield1Border0); jtextfield1.setBackground(new Color(204,178,253)); jtextfield1.setLocation(new Point(87,16)); this.add(jtextfield1); jtextfield3 = new JTextField(); jtextfield3.setToolTipText("Subject"); jtextfield3.setBounds(new Rectangle(88,49,199,21)); Border jtextfield3Border0 = new BevelBorder(1); jtextfield3.setBorder(jtextfield3Border0); jtextfield3.setSize(new Dimension(199,21)); jtextfield3.setName("jtextfield3"); jtextfield3.setBackground(new Color(204,178,253)); jtextfield3.setLocation(new Point(88,49)); jtextfield3.setLayout(null); this.add(jtextfield3); jbutton0 = new JButton(); jbutton0.setPreferredSize(new Dimension(79,45)); jbutton0.setToolTipText("Send"); jbutton0.setBounds(new Rectangle(308,17,143,55)); Border jbutton0Border1 = new EtchedBorder(); Border jbutton0Border0 = new TitledBorder(jbutton0Border1,""); jbutton0.setBorder(jbutton0Border0); jbutton0.setSize(new Dimension(143,55)); jbutton0.setMaximumSize(new Dimension(79,45)); jbutton0.setName("jbutton0"); jbutton0.setForeground(new Color(140,0,140)); jbutton0.setActionCommand("S"); jbutton0.setFont(new java.awt.Font("sansserif", 0, 24)); jbutton0.setText("SEND"); jbutton0.setBackground(new Color(204,178,253)); jbutton0.setMinimumSize(new Dimension(79,45)); jbutton0.setLocation(new Point(308,17)); this.add(jbutton0); // Mouse listener for Button jbutton0.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { SendTheMail(); } } ); jlabel0 = new JLabel(); jlabel0.setPreferredSize(new Dimension(47,24)); jlabel0.setBounds(new Rectangle(9,15,82,24)); jlabel0.setSize(new Dimension(82,24)); jlabel0.setMaximumSize(new Dimension(47,24)); jlabel0.setName("jlabel0"); jlabel0.setFont(new java.awt.Font("serif.bold", 1, 18)); jlabel0.setText("From:"); jlabel0.setMinimumSize(new Dimension(47,24)); jlabel0.setForeground(new Color(0,0,0)); jlabel0.setLocation(new Point(9,15)); jlabel0.setLayout(null); this.add(jlabel0); jlabel1 = new JLabel(); jlabel1.setPreferredSize(new Dimension(63,24)); jlabel1.setBounds(new Rectangle(9,48,84,23)); jlabel1.setSize(new Dimension(84,23)); jlabel1.setForeground(new Color(0,0,0)); jlabel1.setMaximumSize(new Dimension(63,24)); jlabel1.setName("jlabel1"); jlabel1.setFont(new java.awt.Font("serif.bold", 1, 18)); jlabel1.setText("Subject:"); jlabel1.setMinimumSize(new Dimension(63,24)); jlabel1.setLocation(new Point(9,48)); jlabel1.setLayout(null); this.add(jlabel1); textarea0 = new TextArea(); textarea0.setSize(new Dimension(440,190)); textarea0.setName("textarea0"); textarea0.setLocation(new Point(9,93)); textarea0.setText(""); textarea0.setBounds(new Rectangle(9,93,440,190)); textarea0.setForeground(new Color(0,0,0)); textarea0.setBackground(new Color(207,166,255)); textarea0.setFont(new java.awt.Font("serif.bold", 1, 14)); this.add(textarea0); } URL getURL(String txtURL) { // return a URL object given the URL try { if (txtURL == null) return new URL("file://"); else return new URL(txtURL); } catch(MalformedURLException mue) { return null; } } public String[][] getIconPathForComponent(Component comp, String methodName) { // return an Icon path(s) for a given Component/Method { String[][] rval = {{null}}; return rval; } } private String getReference(String[][] references, String methodName) { for (int i = 0; i < references.length; i++) if (references[i][0] == methodName) return references[i][1]; return null; } public void SendTheMail() { new MailerFrame(); } } // end of class Client Panel // ***********************DIALOG BOX PANEL******************************* class MailDialog extends JPanel { public static Color colors0190[] = { new Color(0,0,0) }; // Instance variables public TextArea jtextarea0; public JLabel jlabel0; public JButton jbutton0; public MailDialog() { // Setup GUI this.setBounds(120,85,197,152); this.setSize(new Dimension(197,152)); this.setPreferredSize(new Dimension(1,1)); Border thisBorder0 = new EtchedBorder(); this.setBorder(thisBorder0); this.setName("this"); this.setLocation(new Point(120,85)); this.setMinimumSize(new Dimension(1,1)); this.setToolTipText("Mail Results"); this.setBounds(new Rectangle(120,85,197,152)); this.setForeground(new Color(255,255,255)); this.setBackground(new Color(0,156,166)); this.setLayout(null); jtextarea0 = new TextArea(); jtextarea0.setBounds(new Rectangle(7,31,187,90)); jtextarea0.setEditable(false); jtextarea0.setSize(new Dimension(187,90)); jtextarea0.setName("jtextarea0"); jtextarea0.setForeground(new Color(0,0,0)); jtextarea0.setBackground(new Color(0,156,168)); jtextarea0.setLocation(new Point(7,31)); this.add(jtextarea0); jlabel0 = new JLabel(); jlabel0.setPreferredSize(new Dimension(102,24)); jlabel0.setBounds(new Rectangle(7,3,183,22)); jlabel0.setSize(new Dimension(183,22)); jlabel0.setMaximumSize(new Dimension(102,24)); jlabel0.setName("jlabel0"); jlabel0.setFont(new java.awt.Font("serif.bold", 1, 18)); jlabel0.setText(" Mail Results"); jlabel0.setBackground(new Color(0,156,168)); jlabel0.setForeground(new Color(0,0,0)); jlabel0.setHorizontalAlignment(0); jlabel0.setMinimumSize(new Dimension(102,24)); jlabel0.setLocation(new Point(7,3)); jlabel0.setLayout(null); this.add(jlabel0); jbutton0 = new JButton(); jbutton0.setPreferredSize(new Dimension(33,33)); jbutton0.setBounds(new Rectangle(20,123,158,30)); Border jbutton0Border1 = new EtchedBorder(); Border jbutton0Border0 = new TitledBorder(jbutton0Border1,""); jbutton0.setBorder(jbutton0Border0); jbutton0.setSize(new Dimension(158,30)); jbutton0.setMaximumSize(new Dimension(33,33)); jbutton0.setName("jbutton0"); jbutton0.setForeground(new Color(231,224,233)); jbutton0.setActionCommand("O"); jbutton0.setFont(new java.awt.Font("dialog", 0, 14)); jbutton0.setText("OK"); jbutton0.setBackground(new Color(0,156,168)); jbutton0.setMinimumSize(new Dimension(33,33)); jbutton0.setLocation(new Point(20,120)); this.add(jbutton0); } //end of super URL getURL(String txtURL) { // return a URL object given the URL try { if (txtURL == null) return new URL("file://"); else return new URL(txtURL); } catch(MalformedURLException mue) { return null; } } public String[][] getIconPathForComponent(Component comp, String methodName) { // return an Icon path(s) for a given Component/Method { String[][] rval = {{null}}; return rval; } } private String getReference(String[][] references, String methodName) { for (int i = 0; i < references.length; i++) if (references[i][0] == methodName) return references[i][1]; return null; } } // end class MailDialog // ****************** DIALOG BOX FRAME ************************* class MailerFrame extends JFrame { public static MailDialog md; public MailerFrame() { setTitle("Results"); setBounds(new Rectangle(319,182,520,365)); setSize(210,185); setBackground(new Color(0,156,166)); md = new MailDialog(); getContentPane().add(md); // pack(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { hide(); } public void windowOpened(WindowEvent e) { resize(210,185); repaint(); } } ); // also adding a Mouse listener to the jbutton in the MailDialog JPanel(md) to allow the // user to exit the Dialog box // Mouse listener for Button md.jbutton0.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { hide(); dispose(); } } ); String FROM = EJBMailClient.cp.jtextfield1.getText(); String SUBJECT = EJBMailClient.cp.jtextfield3.getText(); String MESSAGE = EJBMailClient.cp.textarea0.getText(); String USERINFO = "Localhost. Sent using the built-in client for LiL CJs EJBMailDaemon EJB software."; // Finally let's send the mail by simply calling the String SendMail in the EJB's Remote // interface. The string will be displayed in the JTextArea of the MailerFrame (the // JTextArea comes from the JPanel created through md = new MailDialog() ). show(); // showing the JFrame repaint(); setResizable(false); md.jtextarea0.setText("Sending Mail..."); // "wait" text, while we perform the EJB lookup setTitle("Sending..."); try { // performing the EJB lookup Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY,"org.ejboss.naming.spi.EjbossClientContextFactory"); Context ctx = new InitialContext(p); //setting initial context // get a reference to the EJB's home interface EJBMailDaemonHome home = (EJBMailDaemonHome) ctx.lookup("EJBMailDaemon"); // call the EJB's create method to get a reference to the Remote interface EJBMailDaemon mail = home.create(); // now, we can send the mail and get the mail status message in one action. // The mail will be sent when we set the text for the jtextarea0 md.jtextarea0.setText(mail.SendMail(FROM,SUBJECT,MESSAGE,USERINFO)); setTitle("Results"); } catch (Exception e) { md.jtextarea0.setText(e+e.getMessage()); System.out.print(e+e.getMessage()); } } //end super method } //end of class SendMail