Accessing Hardware Devices From a JavaFX Application Using Java API
- Skill Level Intermediate
- Product JavaFX
- Key Features API
- Last Updated May 2009
To access your file system, print from your JavaFX application, or access any other hardware, call the appropriate Java classes in your JavaFX code. The following example illustrates how to use a file chooser (JFileChooser class) in your JavaFX application and it is implemented in the VideoCube example.
Note: The source code example displays a part of the code of the sample. To see the full code, go to the VideoCube sample page and download the VideoCube.fx file.
...
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
...
...
onMouseClicked: function (event) {
rotation.pause();
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(null)) {
source = chooser.getSelectedFile().toURI().toString()
}
rotation.play();
}
...
Java APIs are different between desktop and mobile platforms. On a mobile device, use the appropriate JSR to access your hardware and include the appropriate JSR .jar file in the project. For example, if you want to use the accelerometer on you mobile device, use the JSR 256 Mobile Sensor API for accessing an accelerometer from JavaFX code.
Related Links
We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.
Dmitry Kostovarov
Technical Writer, Sun Microsystems