У меня есть существующий код, над которым я работаю для моего окончательного проекта, и он использует Java-апплет. Когда я компилирую свой код, я получаю три файла с одинаковым именем, но с расширением класса. Когда я запускаю это в терминале, чтобы скомпилировать код
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();
}
}
}
}
// }
//}