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

📄 mainframe.java

📁 一个JFrame实现的邮件客户端
💻 JAVA
字号:
package mailbox;

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;


public class MainFrame extends JFrame {
  BorderLayout borderLayout1 = new BorderLayout();
  JTabbedPane mainTab = new JTabbedPane();
  ConfigPanel configPanel;
  RecievePanel recievePanel;
  SendPanel sendPanel;
  JPanel helpPanel=new JPanel();
  JTextArea helpArea = new JTextArea();
    public MainFrame() {
    try {
             enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(borderLayout1);
    File attachments=new File("附件");
    File emails=new File("邮件夹");
     if(!emails.exists())
      emails.mkdirs();
      if(!attachments.exists())
       attachments.mkdirs();
    
    if((new File("object")).exists())
    {try{ObjectInputStream in2=new ObjectInputStream(new FileInputStream("object"));
    recievePanel=(RecievePanel)in2.readObject();
    configPanel=(ConfigPanel)in2.readObject();
   
    in2.close();
        }
     catch(Exception ioe)
     {
     recievePanel=new RecievePanel();
     configPanel=new ConfigPanel();
     JOptionPane.showMessageDialog(this,"上次退出异常,现在重新加载,你的邮件请在emails文件夹里找");
    }
    }
    else
    {
    recievePanel=new RecievePanel();
    configPanel=new ConfigPanel();
    }
    User.setDisplayName(configPanel.displayField.getText());
    User.setUserName(configPanel.userField.getText());
    User.setPassWord(configPanel.passwordField.getText());
    User.setPop3Server(configPanel.pop3Field.getText());
    User.setSmtpServer(configPanel.smtpField.getText());
    User.setValidateNeeded(configPanel.validateCheckBox.isSelected());
            
    sendPanel=new SendPanel(recievePanel);
    helpPanel.setLayout(null);
    helpArea.setBounds(new Rectangle(60, 28, 439, 325));
    helpArea.setFont(new java.awt.Font("Monospaced", 0, 14));
    String word="                  <SimpleMailBox2.0使用帮助>;\n1.pop3服务器推荐:pop3.163.com;pop3.sohu.com;\n                 pop3.sina.com.cn;pop.21cn.com;\n2.smtp服务器推荐:smtp.163.com;smtp.sohu.com;\n                 smtp.sina.com.cn;smtp.21cn.com;\n3.国内smtp服务器现在大部分都需要用户名密码验证,上述\n  几个都需要验证.请在《邮箱配置》里在'是否需要验证’\n  这一项打上勾,(默认已经选中).\n4.本程序部分采用序列化操作.为避免以外发生,所以在\n  emails文件夹保存着相应的邮件.\n5.请不要删掉各个文件夹和文件,否则,程序将重新初始化.\n6.本程序善不能正确显示html格式的email.\n附:本人邮箱地址为postmaster@netbor.net\n      "                                    ;
    helpArea.setText(word);
      
    this.getContentPane().add(mainTab);
    mainTab.setBackground(SystemColor.inactiveCaptionBorder);
    mainTab.setFont(new java.awt.Font("Monospaced", 0, 14));
    helpPanel.add(helpArea, null);
    mainTab.addTab("使用帮助",helpPanel);
    mainTab.addTab("接收邮件",recievePanel);
    mainTab.addTab("发送邮件",sendPanel);
    mainTab.addTab("邮箱配置",configPanel);
     mainTab.setSelectedIndex(0);
    this.setResizable(false);
    this.setSize(580,440);
    
         }
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
     if (e.getID() == WindowEvent.WINDOW_CLOSING) {
             mainTab.setSelectedIndex(0);
             helpArea.requestFocus();
                        
     try{
    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("object"));
    out.writeObject(recievePanel);
    out.writeObject(configPanel);
    out.close();
    }
    catch(Exception ep){
    ep.printStackTrace();
    }
    System.exit(0);
    }
  }
     
     

}

⌨️ 快捷键说明

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