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

📄 mailget.java

📁 这是一个用Java语言编的一个小程序
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;

public class MailGet extends Applet
{
  public void init()
  {
    setLayout(null);
    setSize(540,393);
    label1=new Label("Server");
    label1.setBounds(60,48,48,12);
    add(label1);
    label2=new Label("User");
    label2.setBounds(60,72,48,12);
    add(label2);
    label3=new Label("Passwd");
    label3.setBounds(48,96,48,12);
    add(label3);
    txtServer=new TextField();
    txtServer.setBounds(108,48,324,23);
    add(txtServer);
    txtUser=new TextField();
    txtUser.setBounds(108,72,324,22);
    add(txtUser);
    txtPass=new TextField();
    txtPass.setEchoChar('*');
    txtPass.setBounds(108,96,324,24);
    add(txtPass);
    cmdGet=new Button();
    cmdGet.setActionCommand("button");
    cmdGet.setLabel("Get");
    cmdGet.setBounds(444,48,68,60);
    cmdGet.setBackground(new Color(12632256));
    add(cmdGet);
    txtReply=new TextArea();
    txtReply.setBounds(60,144,415,213);
    add(txtReply);
    Action lAction=new Action();
    cmdGet.addActionListener(lAction);
  }
  Label label1;
  Label label2;
  Label label3;
  TextField txtServer;
  TextField txtUser;
  TextField txtPass;
  Button cmdGet;
  TextArea txtReply;

 class Action implements ActionListener
 {
   public void actionPerformed(ActionEvent event)
   {
      Object object=event.getSource();
      if(object==cmdGet)
         GetMail(event);
    }
}
  public void GetMail(ActionEvent evt)
  {
    String sHostName;
    int nPort=110;
    String sReply;
    sHostName=txtServer.getText();
    try{
        Socket sktConn=new Socket(sHostName,nPort);
        PrintStream ps=new PrintStream(sktConn.getOutputStream());
        sReply=getReply(sktConn);
        if(sReply.indexOf("+ERR")==-1)
        {
          txtReply.append(sReply+"\n");
          ps.println("USER liulili");
          txtReply.append(getReply(sktConn)+"\n");
          ps.println("PASS"+txtPass.getText());
          txtReply.append(getReply(sktConn)+"\n");
         }
         ps.println("QUIT");
         txtReply.append(getReply(sktConn)+"\n");
      }catch(IOException e){
      System.out.println(e.getMessage());
     }
}
   String getReply(Socket sktConn)
  {
      try{
        BufferedReader outgoing=new BufferedReader(new InputStreamReader(sktConn.getInputStream()));
         return outgoing.readLine();
        }
            catch(IOException e){
            return e.getMessage();
        }
}
   public static void main(String args[])
   {
     Frame f=new Frame("Draw");
     Applet p=new MailGet();
     p.init();
     p.start();
     f.add(p);
     f.setSize(400,300);
     f.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){System.exit(0);
}
});
   f.show();
}
}




⌨️ 快捷键说明

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