无法在MacOS High Sierra

时间:2018-05-06 00:37:18

标签: java applet

我有我正在为我的最终项目工作的现有代码,它使用java applet。当我编译我的代码时,我得到三个具有相同名称但具有类扩展名的文件。当我在终端中运行它来编译代码时

javac -cp .:* SMTPApplet.java

我得到以下

Note: SMTPApplet.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

当我跑

javac -Xlint:deprecation -cp .:* SMTPApplet.java

我明白了

  SMTPApplet.java:9: warning: [deprecation] Applet in java.applet has
  been deprecatedpublic class SMTPApplet extends Applet {
                            ^                1 warning

我一直在尝试和研究,但无法显示小程序。我甚至安装了openJDK,但这没有帮助。

以下是我查看过的网站之一 https://www.cs.colostate.edu/helpdocs/JavaInDOS.html

似乎应该有一个.html文件,我在编译代码时没有得到。我不知道我是否想要获得.html文件。 我还想提一下,我不熟悉Java。 我安装了Java 10,Firefox是我的默认浏览器。  这是我正在处理的代码

import java.applet.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
import java.awt.event.*;
import java.awt.*;

//public class SMTPApplet
public class SMTPApplet extends Applet {

private Button    sendButton   = new Button("Send Message");
private Label     fromLabel    = new Label("From: ");
private Label     subjectLabel = new Label("Subject: ");
private TextField fromField    = new TextField(40);
private TextField subjectField = new TextField(40);
private  TextArea message      = new TextArea(30, 60);
private  String   toAddress = "";

public SMTPApplet() {

this.setLayout(new BorderLayout());

Panel north = new Panel();
north.setLayout(new GridLayout(3, 1));

Panel n1 = new Panel();
n1.add(fromLabel);
n1.add(fromField);
north.add(n1);

Panel n2 = new Panel();
n2.add(subjectLabel);
n2.add(subjectField);
north.add(n2);

this.add(north, BorderLayout.NORTH);

message.setFont(new Font("Monospaced", Font.PLAIN, 12));
this.add(message, BorderLayout.CENTER);

Panel south = new Panel();
south.setLayout(new FlowLayout(FlowLayout.CENTER));
south.add(sendButton);
sendButton.addActionListener(new SendAction());
this.add(south, BorderLayout.SOUTH);

}

public void init() {

String subject = this.getParameter("subject");
if (subject == null) subject = "Hi";
subjectField.setText(subject);

toAddress = this.getParameter("to");
if (toAddress == null) toAddress = "";

String fromAddress = this.getParameter("from");
if (fromAddress == null) fromAddress = "";
fromField.setText(fromAddress);

}

class SendAction implements ActionListener {

public  void actionPerformed(ActionEvent evt) {

  try {
    Properties props = new Properties();
    props.put("mail.host", getCodeBase().getHost());

    Session mailConnection = Session.getInstance(props, null);
    final Message msg = new MimeMessage(mailConnection);

    Address to = new InternetAddress(toAddress);
    Address from = new InternetAddress(fromField.getText());

    msg.setContent(message.getText(), "text/plain");
    msg.setFrom(from);
    msg.setRecipient(Message.RecipientType.TO, to);
    msg.setSubject(subjectField.getText());

    // This can take a non-trivial amount of time so
    // spawn a thread to handle it.
    Runnable r = new Runnable() {
      public void run() {
        try {
          Transport.send(msg);
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    };
    Thread t = new Thread(r);
    t.start();

    message.setText("How are you?");
  }
  catch (Exception ex) {
    // We should really bring up a more specific error dialog here.
    ex.printStackTrace();
                }
            }
        }
    }
//    }
//}

0 个答案:

没有答案