如何链接JGraph传感器和Java邮件?
我在链接jgraph和java邮件时遇到了一个问题。该程序是关于,如果温度超过60摄氏度,该程序将向我的电子邮件发送警报。问题是,我不知道如何调用捕获的数据温度如何链接JGraph传感器和Java邮件?,java,netbeans,arduino,Java,Netbeans,Arduino,我在链接jgraph和java邮件时遇到了一个问题。该程序是关于,如果温度超过60摄氏度,该程序将向我的电子邮件发送警报。问题是,我不知道如何调用捕获的数据温度 public void actionPerformed(ActionEvent arg0){ if(connectButton.getText().equals("Connect")){ **//attempt to connect the serial port** choosenPort = Ser
public void actionPerformed(ActionEvent arg0){
if(connectButton.getText().equals("Connect")){
**//attempt to connect the serial port**
choosenPort = SerialPort.getCommPort(portlist.getSelectedItem().toString());
choosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
if(choosenPort.openPort()){
connectButton.setText("Disconnect");
portlist.setEnabled(false);
}
**//create a new thread that listen for incoming text and populates the graph**
Thread thread = new Thread(){
public void run(){
Scanner scanner = new Scanner(choosenPort.getInputStream());
int x = 0;
while(scanner.hasNextLine()){
try{
String line = scanner.nextLine();
int number =Integer.parseInt(line);
series.add(x++, number * 0.488);
window.repaint();
**// mail sent to the owner**
if(x> 50){
String host = "smtp.gmail.com";
final String user = "xxxxx.gmail.com";
final String pass = "xxxxxxx";
String to = "xxxx.gmail.com";
String from = "xxxx.gmail.com";
String subject ="Smart Alarm Emergency";
String messageText ="this is try message";
boolean sessionDebug = false;
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Session mailSession =Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(to));
InternetAddress[] address ={ new InternetAddress(to)};
msg.setRecipients (Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pass);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
System.out.println("Sent Succesfully");
}else{
}
}catch (Exception e){
}
}
scanner.close();
}
};
thread.start();
}else{
//attempt to disconnect the serial port
choosenPort.closePort();
portlist.setEnabled(true);
connectButton.setText("Connect");
series.clear();
}
}
});
那个空的
else{}
语句是无用的。@DonaldDuck我忘了去掉它,还有,这是Javascript还是Java?标题表示它是Java,标签表示它是Javascript。Javascript和Java是两种完全不同的语言。如果它是Java(可能是因为它看起来不像我所知道的任何Javascript),请相应地重新标记它。@DonaldDuck done mate,对不起