我正在用java编写一个简单的多线程练习。我需要做的就是制作一个带有两个按钮(“开始”和“结束”)的 JFrame。如果用户点击“开始”按钮,控制台将开始打印“打印”。如果单击“结束”,控制台将停止打印。再次单击“开始”将恢复打印。
这是我的代码(不相关部分未显示):
//import not shown
public class Example extends JFrame implements Runnable {
private static boolean print, started;//print tells whether the thread should keep printing
//things out, started tells whether the thread has been
//started
private JButton start;//start button
private JButton end;//end button
private static Thread thr;//the thread that is going to do the printing
//other fields not shown
public Example(String title) {
Container c = getContentPane();
//set up the JFrame
//...parts not shown
start = new JButton("Start");
end …Run Code Online (Sandbox Code Playgroud) 我正在做一个应用程序,它用 Java 发送电子邮件作为我的计算机科学课程的最终项目。正如许多在线教程所说,我已经导入了可以在此页面下载的所有内容:https : //javaee.github.io/javamail/#Download_JavaMail_Release ,这些 jar 文件都在我的类路径中。我完全按照教程进行操作,但是,由于某种原因,我仍然收到错误消息。这是 SendEmail 类的代码:
import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
import javax.swing.*;
public class sendEmail {
public sendEmail() {
}
protected void send(String sender, String recipient, String password, String subject, String content) {
Properties prop = new Properties();
prop.put("mail.stmp.auth*", "true");// set the authentication to true
prop.put("mail.stmp.starttls.enable*", "true ");
prop.put("mail.stmp.host*", "stmp.gamil.com");
prop.put("mail.stmp.port*", "587");
Session ses = Session.getInstance(prop, new javax.mail.Authenticator() {
private PasswordAuthentication getPassWordAuthrntication() {
return new PasswordAuthentication(sender, password);
}
}); …Run Code Online (Sandbox Code Playgroud)