This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.

ankush dixit

Greenhorn
+ Follow
since Mar 14, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by ankush dixit

hey this is something i wrote for one of our project... i know its not good to give code away... but couldn't resist as i think its a similar problem...

i hope the this still works... but it helped me in the coding the actual requirement...

just a few points to remember - keyPress will press the key so you might have to release it again by keyRelease...

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.IOException;

public class RobotApp {

public static void main(String[] args) {
try {

Process p = Runtime.getRuntime().exec("notepad");

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_L);
robot.keyRelease(KeyEvent.VK_L);
robot.keyPress(KeyEvent.VK_L);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_W);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_R);
robot.keyPress(KeyEvent.VK_L);
robot.keyPress(KeyEvent.VK_D);

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_CONTROL);

robot.keyPress(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_C);
robot.keyPress(KeyEvent.VK_DECIMAL);
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_X);
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_ENTER);

robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F4);
robot.keyRelease(KeyEvent.VK_ALT);

} catch (AWTException awte) {
// do something
} catch (IOException ioe) {
// do something
}
}
}
18 years ago
it means that if a thread(which has access to someobject's lock) enters synchronized block others threads have to wait...
i�m not sure what�s in you m2 method but since you are explicitly handling SQLException and ClassNotFoundExcepion in your m2 method so there is no need to declare them in throws clause...

just remember that every method should catch and handle all checked exception or throw it to the calling method which should do the same...
18 years ago
hi...

i am having problem with sending mails with attachment and message....

i'm able to send mail with message and no attachment and also with attachment and no message...but not both at the same time...

here's the code...

import java.util.Properties;

import javax.mail.Session;
import javax.mail.Message;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;


public class EmailNotification {

public EmailNotification() {

}

public static void sendMail(String to,String from, String subject, String message, String attachmentFileName){
Properties props = new Properties();

String host = "<host name>";

props.put("mail.smtp.host",host);

Session session = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(session);

try {
msg.setFrom(new InternetAddress(from));

InternetAddress[] address =null ;
address=InternetAddress.parse(to);
msg.setRecipients(Message.RecipientType.TO, address);

BodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();

msg.setSubject(subject);


DataSource source = new FileDataSource(attachmentFileName);
messageBodyPart.setDataHandler(new DataHandler(source));
String fileApper = attachmentFileName.substring(attachmentFileName.lastIndexOf("\\")+1);
messageBodyPart.setFileName(fileApper);
messageBodyPart.setText(message);
multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);


Transport.send(msg);
}
catch(AddressException ae){

}
catch(MessagingException me) {

}

}
}
19 years ago