⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maildisplayui.java

📁 自己编写的邮件管理系统程序源代码,方便管理自己的邮件
💻 JAVA
字号:
package mail.ui;import java.awt.Color;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.LinkedList;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JEditorPane;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import mail.message.MailMessage;public class MailDisplayUI extends JFrame implements ActionListener,ItemListener{    JLabel labSubjectDisplayTitle = new JLabel();    JLabel labSubject = new JLabel();    JLabel labFrom = new JLabel();    JLabel labFromDisplayTitle = new JLabel();    JEditorPane taMailContent = new JEditorPane();    JScrollPane jspMailContent=new JScrollPane(taMailContent);        JPanel panelAttach = new JPanel();    JButton bClose = new JButton();    JButton bReply = new JButton();    JButton bTSend = new JButton();    /**     * 邮件客户端     */    private MailClientUI mailClient;        private MailMessage nowMailItem=null;        public MailDisplayUI(MailClientUI mailClient)    {        initUI();        this.mailClient = mailClient;    }    private void initUI()    {        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JFrame.setDefaultLookAndFeelDecorated(true);                labSubjectDisplayTitle.setBorder(BorderFactory                .createLineBorder(Color.black));        labSubjectDisplayTitle.setText("     主题:");        labSubjectDisplayTitle.setBounds(new Rectangle(20, 18, 56, 32));        this.getContentPane().setLayout(null);        labSubject.setBorder(BorderFactory.createLineBorder(Color.black));        labSubject.setBounds(new Rectangle(95, 18, 385, 32));        labFrom.setBounds(new Rectangle(95, 57, 385, 32));        labFrom.setBorder(BorderFactory.createLineBorder(Color.black));        labFromDisplayTitle.setBounds(new Rectangle(20, 55, 56, 32));        labFromDisplayTitle.setBorder(BorderFactory                .createLineBorder(Color.black));        labFromDisplayTitle.setText(" 发信人:");        jspMailContent.setBorder(BorderFactory.createLineBorder(Color.black));        taMailContent.setBounds(new Rectangle(21, 102, 458, 214));        jspMailContent.setBounds(new Rectangle(21, 102, 458, 214));        panelAttach.setBorder(BorderFactory.createLineBorder(Color.black));        panelAttach.setBounds(new Rectangle(20, 327, 458, 75));        bClose.setBackground(Color.white);        bClose.setBorder(BorderFactory.createLineBorder(Color.black));        bClose.setText("关闭");        bClose.setBounds(new Rectangle(100, 420, 100, 31));        bReply.setBackground(Color.white);        bReply.setBorder(BorderFactory.createLineBorder(Color.black));        bReply.setText("回复");        bReply.setBounds(new Rectangle(210, 420, 100, 31));        bTSend.setBackground(Color.white);        bTSend.setBorder(BorderFactory.createLineBorder(Color.black));        bTSend.setText("转发");        bTSend.setBounds(new Rectangle(320, 420, 100, 31));               this.getContentPane().setBackground(Color.lightGray);        this.getContentPane().add(labSubjectDisplayTitle, null);        this.getContentPane().add(labFromDisplayTitle, null);        this.getContentPane().add(jspMailContent, null);        this.getContentPane().add(labFrom, null);        this.getContentPane().add(labSubject, null);        this.getContentPane().add(panelAttach, null);        this.getContentPane().add(bReply, null);        this.getContentPane().add(bTSend, null);        this.getContentPane().add(bClose, null);                panelAttach.setLayout(null);        this.bClose.addActionListener(this);        this.bReply.addActionListener(this);        this.bTSend.addActionListener(this);                this.setSize(520,500);        this.setTitle("显示邮件信息窗口");        this.setLocation(100,50);      }      public static void main(String[] args)      {          new MailDisplayUI(new MailClientUI()).setVisible(true);      }      public void actionPerformed(ActionEvent e)      {          if(e.getSource().equals(this.bClose))          {              close();          }          else if(e.getSource().equals(this.bReply))          {              reply();          }          else if(e.getSource().equals(this.bTSend))          {              tSend();          }else          {          }      }      /**       * 显示邮件       * @param item       */      public void displayMailMessage(MailMessage item)      {          nowMailItem=item;                    this.labFrom.setText(item.getFrom());          this.labSubject.setText(item.getSubject());          if(item.getContent()!=null&&item.getContent().equals("html"))              this.taMailContent.setContentType("text/html");          else              this.taMailContent.setContentType("text/plain");                    this.taMailContent.setText(item.getContent());             panelAttach.removeAll();          LinkedList list=item.getAttachList();          if(item.isFlag()==true&&list!=null)          {              for(int i=0;i<list.size();i++)              {                    JCheckBox jcb=new JCheckBox((String)list.get(i));                    jcb.setBounds(new Rectangle(20, i*18, 430, 18));                    jcb.addItemListener(this);                    jcb.setBackground(Color.WHITE);                    panelAttach.add(jcb);              }          }          panelAttach.updateUI();          this.setVisible(true);      }      /**       * 保存附件       */      public void itemStateChanged(ItemEvent e)       {          for(int i=0;i<panelAttach.getComponentCount();i++)          {             JCheckBox jcb=(JCheckBox)panelAttach.getComponent(i);             if(jcb.isSelected()==true)             {                 JFileChooser fc=new JFileChooser();                 int result=fc.showSaveDialog(this);                 if(result==JFileChooser.APPROVE_OPTION)                 {                                       File nowdir = new File(".").getAbsoluteFile();                     String dirString = nowdir.toString();                     String subs = dirString.substring(0, dirString.length() - 1);                     File tempDir = new File(subs + "info/enclosure/");                     File filename=new File(tempDir,jcb.getText());                                          boolean flag=copy(filename,fc.getSelectedFile());                     if(flag==true) jcb.setBackground(Color.PINK);                     else                     {                         jcb.setSelected(false);                         jcb.setBackground(Color.WHITE);                     }                 }else                 {                     jcb.setSelected(false);                     jcb.setBackground(Color.WHITE);                 }                              }          }          panelAttach.updateUI();      }      /**       * 拷贝文件       * @return       */      public boolean copy(File source,File dest)      {          try          {              if(source.equals(dest))  return true;                            FileInputStream fin=new FileInputStream(source);              FileOutputStream fout=new FileOutputStream(dest);              int count,n=1024;              byte[] buffer=new byte[n];              count=fin.read(buffer,0,n);              while(count!=-1)              {                 fout.write(buffer,0,count);                 count=fin.read(buffer,0,n);              }              fin.close();              fout.close();              return true;          }catch(Exception e)          {              e.printStackTrace();              return false;          }      }      /**       * 关闭窗口       *       */        private void close()      {          this.setVisible(false);      }      /**       * 回复       *       */      private void reply()      {          mailClient.getSendUI().replyMailMessage(nowMailItem);          this.setVisible(false);      }      /**       * 转发该邮件       *       */      private void tSend()      {          mailClient.getSendUI().TSendMailMessage(nowMailItem);          this.setVisible(false);      }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -