Desktop is a useful class in Java. It can be used to open the default browser for a specified url, open a default mail client with optional e-mail address, open a file for editing or viewing, and send a file to the default printer.
To do such operatons mentioned above, first you need to create an object of the Desktop class by using the getDesktop method.
Desktop dt=Desktop.getDesktop();
To launch the default browser on your computer with a specified url, you will use the browse method. The browse method has one argument that is a uri object referencing to the url. To obtain the uri object, you have to create a url object that accepts the address of a web page. Then use the toURI method to convert the url object to uri object. The example code below will open the default browser and shows the http://javatheprogram.blogspot.com address on its address box.
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
public class DesktopDemo {
public static void main(String args[]){
//openMail();
try {
URL url=new URL("http://javatheprogram.blogspot.com");
openBrowser(url.toURI());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//openFile("d:/chart.pdf");
}
public static void openBrowser(URI uri){
Desktop dt=Desktop.getDesktop();
if(Desktop.isDesktopSupported()){
try {
dt.browse(uri);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
You can launch an e-mail client program with your specified e-mail address by using the mail method. The mail method accepts one value that is the uri object. When you construct an url object to refer to an e-mail address, the string that will be passed to the URL constructor takes this form: "mailto:e-mail_addresss". The example below will open the e-mail client program with the e-mail address yuk.dara@gmail.com on you machine.
public static void openMail(){
try {
URL url=new URL("mailto:yuk.dara@gmail.com");
Desktop dt=Desktop.getDesktop();
if(Desktop.isDesktopSupported()){
dt.mail(url.toURI());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
To open a file on your local computer, you will use the open method. This method will take the file object that references to a file on your computer. The code below opens the test.txt file (in drive D) of the computer.
dt.open(new File("d://test.txt"));
If you wan to print the file to the default printer that connects to your computer, you can use the print method. This method also accepts the file object that you want to print. The following code will print the file chart.pdf to the default printer.
dt.print(new File("d:/chart.pdf"));
Please Upload an file that related to the post.and put the download link below the post... :)
ReplyDeletePlease copy and paste.
DeleteI know but sometimes i cannot combine it to a complete file, because i am poor about java :(
ReplyDeletehbjhbjhb
ReplyDeleteThis type of lesson on Javacript will make the students to become an expert Java developer.There are many lessons available in the online market place but the appropriate way of learning the different procedure of making Javascript like as http://www.procustomwriting.com/custom-research-papers is so different from the traditional way.Many people are looking to learn the Desktop class regarding the Javascript.
ReplyDeleteClick the link https://www.thewritingkid.com/academic-writing/ to save your time and manage everything. It is the best service for writing work for students and scientists. They can write about everything what your need and following your instructions to the end. Great team!
ReplyDeleteScience Channel’s Are Giving A Complete Knowledge To Its Viewers About Every Thing Students Write Done Dissertation On This Subjects And Show Its Importance.
ReplyDeleteThis Is Really Great Work. Thank You For Sharing Such A Good And Useful Information Here In The Blog For Students.
ReplyDeleteVery useful info, thanks
ReplyDeleteHi! This is kind of off topic but I need some advice from an established post. Is it hard to set up your own post? I'm not very techincal but I can figure things out pretty quick. I'm thinking about creating my own but I'm not sure where to start. Do you have any tips or suggestions? Appreciate it seo firm singapore
ReplyDeleteThis article has suggested to me many new ideas. I will embark on doing it. Hope you can continue to contribute your talents in this area. Thank you.
ReplyDeleteI and my guys were actually examining the great procedures on your web blog and so suddenly came up with an awful feeling I had not expressed respect to the site owner for them. Most of the guys were definitely as a consequence thrilled to read all of them and have now absolutely been loving these things. Thanks for being indeed accommodating and also for choosing this form of remarkable tips most people are really eager to discover. Our own sincere apologies for not saying thanks to you sooner.digital marketing services
ReplyDeleteAstounding post about the English things. A few people basically leave all kind of affects and go for the outing. I feel cheerful that visit page you go for the outing and I am certain your mind before long feels better.
ReplyDeleteI am typically to running a blog and i really respect your content. The article has actually peaks my interest. I'm going to bookmark your web site and keep checking for brand spanking new information.golf courses western sydney
ReplyDeleteYour home is valueble for me. Thanks!… search advertising singapore
ReplyDeleteGreat one to read.
ReplyDeleteBANGALORE TO TIRUPATI PACKAGE
BANGALORE TO TIRUPATI CAR PACKAGES
BANGALORE TO TIRUPATI TOUR PACKAGE
BANGALORE TO TIRUPATI TOUR PACKAGES
BEST TIRUPATI PACKAGE FROM BANGALORE
BANGALORE TO TIRUPATI PACKAGES
ONE DAY TIRUPATI PACKAGE FROM BANGALORE
TIRUPATI BALAJI DARSHAN PACKAGE FROM BANGALORE
BANGALORE TO TIRUPATI TOUR PACKAGES
BANGALORE TO TIRUPATI CAR PACKAGE
Best Car Package from Bangalore to Tirupati
Tirupati Balaji Darshan Package from Bangalore
Tirupati Trip from Bangalore
car package from bengaluru to tirupati
bangalore to tirumala tour
Tirupati Trip from Bangalore
Bangalore to Tirupati Quick Darshan Package
Bangalore to Tirupati Family Package
Bangalore to Tirupati Package Tour
Bangalore to Tirumala Package
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be giving us something enlightening to read? dental implant singapore
ReplyDeleteFantastic blog! Do you have any recommendations for aspiring writers? I'm planning to start my own site soon but I'm a little lost on everything. Would you advise starting with a free platform like Wordpress or go for a paid option? There are so many options out there that I'm totally confused .. Any ideas? Thank you!
ReplyDeletegolf clubs sydney
Great i Love the article most
ReplyDeleteHindi News
Hindi Sad Shayari
Wordpress in hindi
South Indian Hindi Dubbed Movies
The third hacker full movie
KGF chapter 2
Woah! I'm really loving the template/theme of this blog. It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb usability and visual appeal. I must say you have done a very good job with this. Additionally, the blog loads super fast for me on Chrome. Exceptional Blog! Interior Designers Singapore
ReplyDeleteHave you ever thought about adding a little bit more than just your articles? I mean, what you say is valuable and everything. But just imagine if you added some great visuals or video clips to give your posts more, "pop"! Your content is excellent but with pics and video clips, this website could undeniably be one of the most beneficial in its niche. Excellent blog
ReplyDeletebuy mattress singapore
A ton of much obliged for the entirety of your persistent effort on this site. Betty truly cherishes doing web exploration and it is evident why. My life partner and I become familiar with about the dynamic medium you present great recommendations on your web blog and too welcome reaction from others on the article while my little girl is truly being instructed to such an extent. Exploit the remainder of the year. You are doing a truly incredible work.
ReplyDeletecleaning service company
My significant other and I were very tranquil when Albert figured out how to wrap up his fundamental exploration through the valuable proposals he was given out of the site pages. It is sometimes baffling just to consistently be parting with directions which different people have been bringing in cash from. We truly recollect that we need you to express gratefulness to for this. The delineations you have made, the clear blog route, the companionships your webpage help induce - it has generally incredible, and it's truly driving our child notwithstanding us feel that the present circumstance is cool, and that is phenomenally significant. A debt of gratitude is in order for the entire thing!
ReplyDeleteenergy supplements
Well it seems like your site ate my first remark (it was too long) so I surmise I'll simply summarize it what I composed and state, I'm altogether making the most of your blog. I also am a hopeful blog author however I'm still new to the entire thing. Do you have any tips for amateur blog essayists? I'd like it
ReplyDeletesafe deposit box
Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your site? My website is in the exact same area of interest as yours and my visitors would definitely benefit from a lot of the information you present here. Please let me know if this ok with you. Thank you!bedding singapore
ReplyDeleteThanks on your marvelous posting! I truly enjoyed reading it, you happen to be a great author.I will be sure to bookmark your blog and will come back later on. I want to encourage one to continue your great work, have a nice weekend!korean cosmetics
ReplyDeleteWe are a group of volunteers and opening a new scheme in our community. Your site offered us with valuable information to work on. You've done a formidable job and our entire community will be grateful to you.personalised journal
ReplyDeletehi!,I like your writing so much! share we communicate more about your post on AOL? I require an expert on this area to solve my problem. May be that's you! Looking forward to see you.private debt consolidation lenders
ReplyDeleteThis very helpful advice within this article! It’s the little changes which will make the most significant. Many thanks for sharing! Also visit post utme past questions in mewar university masaka
ReplyDelete