I have existing code that I am working on for my final project and it uses java applet. When I compile my code I get three files with same name but have extension of class. When I run this in terminal to compile the code
javac -cp .:* SMTPApplet.java
I get the following
Note: SMTPApplet.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
and when I run
javac -Xlint:deprecation -cp .:* SMTPApplet.java
I get this
SMTPApplet.java:9: warning: [deprecation] Applet in java.applet has
been deprecatedpublic class SMTPApplet extends Applet {
^ 1 warning
I have been trying and researching, but couldn't get the applet to display. I even installed openJDK, but this didn't help.
Here are one of the websites I looked at https://www.cs.colostate.edu/helpdocs/JavaInDOS.html
It seems this is there should be a .html file which I am not getting when I compile my code. I don't know if I am suppose to get .html file or not. I also want to mention that I am not familiar with Java. I have Java 10 installed and Firefox my default browser. Here is the code I am working on
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();
}
}
}
}
// }
//}