📄 mainframe.java
字号:
jTabbedPane1.addTab("\u914d\u7f6e\u5ba2\u6237\u7aef", jPanel2);
MailList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
MailList.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
MailListMouseClicked(evt);
}
});
jScrollPane2.setViewportView(MailList);
jButton1.setText("\u83b7\u53d6\u90ae\u4ef6\u5217\u8868");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("\u70b9\u51fb\u67e5\u770b\u8be6\u7ec6\u4fe1\u606f");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel8.setText("\u53d1\u4fe1\u4eba");
jLabel9.setText("\u4e3b\u9898");
org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel3Layout.createSequentialGroup()
.add(55, 55, 55)
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(102, 102, 102)
.add(jButton2)
.add(103, 103, 103))
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)
.add(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(91, 91, 91)
.add(jLabel9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
.add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
.add(jLabel9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 301, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton1)
.add(jButton2))
.addContainerGap())
);
jTabbedPane1.addTab("\u6536\u4ef6\u7bb1", jPanel3);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO 将在此处添加您的处理代码:
int index=MailList.getSelectedIndex();
try{
getter.getMailAttach(index);
}catch(IOException e)
{
System.out.println(e);
}catch(MessagingException e)
{
System.out.println(e);
}
}//GEN-LAST:event_jButton2ActionPerformed
private void MailListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MailListMouseClicked
// TODO 将在此处添加您的处理代码:
if(evt.getClickCount()==2)
{
int index=MailList.getSelectedIndex();
try{
getter.getMailAttach(index);
}catch(IOException e)
{
System.out.println(e);
}catch(MessagingException e)
{
System.out.println(e);
}
}
}//GEN-LAST:event_MailListMouseClicked
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO 将在此处添加您的处理代码:
try{
getter=new getMail(pop3,username,password);
list=getter.vecMailList();
MailList.setListData(list);
MailList.updateUI();
}catch(NoSuchProviderException e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null,"找不到对应的服务器!","Error",JOptionPane.NO_OPTION);
}
}//GEN-LAST:event_jButton1ActionPerformed
private boolean MailInfo(){
from=tf_sender.getText().trim();
to=tf_Getter.getText().trim();
subject=tf_Subject.getText().trim();
filename=tf_FileName.getText().trim();
content=ta_content.getText().trim();
if(filename!=null&&filename!="")
{
attachment=true;
}
if(from!=null&&from!=""&&to!=null&&to!=""&&subject!=null&&subject!=""&&content!=null&&content!="")
return true;
else
return false;
}
private void btn_sendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_sendActionPerformed
// TODO 将在此处添加您的处理代码:
if(!config)
{
JOptionPane.showConfirmDialog(null,"请配置好客户端的相关内容!","警告",JOptionPane.OK_OPTION,JOptionPane.WARNING_MESSAGE);
return;
}
if(MailInfo()&&CheckEmailFormat(from)&&CheckEmailFormat(to))
{
sender=new sendMail(smtp);
sender.setNamePass(username,password);
if(needAuth)
{
sender.setNeedAuth(true);
}
sender.setSubject(subject);
sender.setBody(content);
sender.setFrom(from);
sender.setTo(to);
if(attachment)
{
if(!sender.addFileAffix(filename))
{
JOptionPane.showConfirmDialog(null,"无法添加指定附件,请确认文件的正确性!","警告",JOptionPane.OK_OPTION,JOptionPane.WARNING_MESSAGE);
}
}
if(sender.sendout())
{
JOptionPane.showConfirmDialog(null,"文件已经完整发送!","信息",JOptionPane.OK_OPTION,JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showConfirmDialog(null,"邮件发送失败!~~~~~","警告",JOptionPane.OK_OPTION,JOptionPane.WARNING_MESSAGE);
}
}
}//GEN-LAST:event_btn_sendActionPerformed
private void btn_ComfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ComfirmActionPerformed
// TODO 将在此处添加您的处理代码:
smtp=tf_smtp.getText().trim();
pop3=tf_pop3.getText().trim();
username=tf_username.getText().trim();
password=tf_userpassword.getText().trim();
if(smtp!=null&&smtp!=""&&pop3!=null&&pop3!=""&&username!=null&&username!=""&&password!=null&&password!="")
config=true;
else
config=false;
try{
jTabbedPane1.setSelectedIndex(0);
}catch(IndexOutOfBoundsException e)
{
System.out.println(e);
}
}//GEN-LAST:event_btn_ComfirmActionPerformed
private void cb_AnthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_AnthActionPerformed
// TODO 将在此处添加您的处理代码:
}//GEN-LAST:event_cb_AnthActionPerformed
private void cb_AnthMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cb_AnthMouseClicked
// TODO 将在此处添加您的处理代码:
if(cb_Anth.isSelected())
{
needAuth=true;
}
else
needAuth=false;
if(needAuth)
{
tf_username.setEditable(true);
tf_userpassword.setEditable(true);
}
else
{
tf_username.setEditable(false);
tf_userpassword.setEditable(false);
tf_username.setText("");
tf_userpassword.setText("");
username="";
password="";
}
}//GEN-LAST:event_cb_AnthMouseClicked
private void btn_quitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_quitActionPerformed
// TODO 将在此处添加您的处理代码:
int exi;
exi=JOptionPane.showConfirmDialog(this,"客户端将退出,请确认?","退出程序",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(exi==JOptionPane.YES_OPTION)
{
System.exit(0);
}
return;
}//GEN-LAST:event_btn_quitActionPerformed
private void btn_clearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_clearActionPerformed
// TODO 将在此处添加您的处理代码:
clear();
}//GEN-LAST:event_btn_clearActionPerformed
private void openFile(){
JFileChooser chooser=new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setCurrentDirectory(new File("c:\\"));
int returnVal = chooser.showOpenDialog(this);
if(returnVal==chooser.APPROVE_OPTION)
{
File file=chooser.getSelectedFile();
String filename=file.getAbsolutePath();
tf_FileName.setText(filename);
System.out.println(filename);
}
else
return ;
}
private void clear(){
tf_sender.setText("");
tf_Getter.setText("");
tf_Subject.setText("");
ta_content.setText("");
tf_FileName.setText("");
}
private void btn_addFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_addFileActionPerformed
// TODO 将在此处添加您的处理代码:
openFile();
}//GEN-LAST:event_btn_addFileActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
MainFrame app=new MainFrame();
app.setSize(600,450);
app.setLocation(100,100);
app.setVisible(true);
}
});
}
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JList MailList;
private javax.swing.JButton btn_Comfirm;
private javax.swing.JButton btn_addFile;
private javax.swing.JButton btn_clear;
private javax.swing.JButton btn_quit;
private javax.swing.JButton btn_send;
private javax.swing.JCheckBox cb_Anth;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextArea ta_content;
private javax.swing.JTextField tf_FileName;
private javax.swing.JTextField tf_Getter;
private javax.swing.JTextField tf_Subject;
private javax.swing.JTextField tf_pop3;
private javax.swing.JTextField tf_sender;
private javax.swing.JTextField tf_smtp;
private javax.swing.JTextField tf_username;
private javax.swing.JPasswordField tf_userpassword;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -