AWT / NOTES</>↗AWT19 Apr 2010
For editing a file using the default registered or associated application we can do a call to the java.awt.Desktop.edit(File) method. In the code snippet below we will edit a PNG file. Using the edit() method of the Desktop class will open the default registered application for PNG files. For example on Windows there could be […]
AWT / NOTES</>↗AWT16 Apr 2010
If you want to open a file using the default registered or associated application for those files you can use the Desktop.open(File file) method call. In the example below we’ll ask the Desktop class to open a text file. package org.kodejava.awt; import java.awt.*; import java.io.File; import java.io.IOException; public class RunningDefaultAppOpen { public static void main(String[] […]
AWT / NOTES</>↗AWT15 Apr 2010
Here is an example using the java.awt.Desktop class to open user’s default mail client application. There are two methods provided, the mail() and the mail(URI uri) methods. When specifying the URI to the application will be opened with the message field filled with the mailto information. You can refer to the following document for the […]
AWT / NOTES</>↗AWT14 Apr 2010
The code below show you how to browse a website using the user’s default web browser. To get the default web browser you can use the Desktop class browse(URI uri) method call. package org.kodejava.awt; import java.awt.Desktop; import java.io.IOException; import java.net.URI; public class RunningDefaultBrowser { public static void main(String[] args) { URI uri = URI.create("https://kodejava.org"); try […]
APPLET / NOTES</>↗Applet10 Apr 2010
To display an image in an applet we first need to obtain the image object itself. A call to applet’s getImage(URL url, String name) method help us to create an image object from the specified URL of the image. For displaying the image on the applet’s screen we draw it in the paint() method using […]
APPLET / NOTES</>↗Applet05 Apr 2010
The code snippet below show you how to get the URL of the document (HTML, JSP, etc.) where the Applet is embedded. To obtain this document URL we use the getDocumentBase() method call provided by the Applet class. In the paint() method below we use the getDocumentBase() to create a URL as a link to […]