Language - Java Linux Eclipse: Difference between revisions

From Phidgets Support
No edit summary
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{NoTitle}}
[[Category:Language]]{{NoTitle}}
{{Language_-_Java_Dev_Environment_Table}}
{|
{|
|style="vertical-align:middle; width: 60%;"|
|style="vertical-align:middle; width: 60%;"|
Line 16: Line 15:
#You will need a copy of [{{SERVER}}/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]
#You will need a copy of [{{SERVER}}/downloads/phidget22/libraries/any/Phidget22Java.zip phidget22.jar]


==Use Our Examples==
{{Finding Code Samples|Java}}
One of the best ways to start programming with Phidgets is to use our example code as a guide. In order to run the examples, you will need to download and install [https://www.eclipse.org/downloads/ Eclipse].
 
 
Now that you have Eclipse installed, select an example that will work with your Phidget:
*{{SampleCode|Java|Java Examples}}
 
 
Next, create a new Java project. Give it the same name as the example you downloaded above:
 
[[Image:Java_eclipse_linux_newproject.PNG|link=| center|500px]]
 
 
Click ''Next >'' then ''Add External JARs...'' and add phidget22.jar to your project as an external jar:
[[Image:Java_eclipse_linux_addjar.PNG|link=| center|500px]]
 
 
Finally, drag the example java file into the src folder that has been created for you and run the example:
 
[[Image:Java_eclipse_linux_run.png|link=|center|700px]]
 
 
Before you run the example, you may need to set up your Udev rules. An explanation on how to do this is provided on the Linux OS page, which can be accessed [[OS - Linux#Setting udev Rules | here]].
 
 
{{Edit_the_Examples}}
 
==Editing the Examples==
{{Language_-_Java_Editing_the_Examples}}
 
==Write Code==
{{Language_-_Java_Write_Code}}


==Setting up a New Project==
==Setting up a New Project==
When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget Java library.
When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget Java library.


To begin, create a new Java project:
To begin, create a new Java project. Give it a name, then click ''Next >'':


[[Image:Java_eclipse_linux_newproject.PNG|link=| center |500px]]
[[Image:Java_eclipse_linux_newproject.PNG|link=| center |500px]]




Click ''Next >'' then ''Add External JARs...'' and add phidget22.jar to your project as an external jar:
Go to the ''Libraries'' tab and click ''Add External JARs...'' and add phidget22.jar to your project as an external jar:
[[Image:Java_eclipse_linux_addjar.PNG|link=| center|500px]]
[[Image:Java_eclipse_linux_addjar.PNG|link=| center|500px]]


Line 69: Line 37:




Finally, to use the Phidget Java library, add the following import to the top of your code:
The project now has access to Phidgets.
<syntaxhighlight lang="java">
import com.phidget22.*;
</syntaxhighlight>


The project now has access to Phidgets.
{{Using the Code Samples|Java|Linux|Eclipse}}


==Further Reading==
{{Language Page What's Next}}
{{Language_-_Java_Further_Reading}}

Revision as of 22:21, 16 October 2019

Language - Java

Linux with Eclipse

Welcome to using Phidgets with Java! By using Java, you will have access to the complete Phidget22 API, including events.

Eclipse is an IDE used to write, compile, and run Java applications.

Install Phidget Drivers for Linux

Before getting started with the guides below, ensure you have the following components installed on your machine:

  1. You will need the Phidgets Linux Drivers
  2. You will need the Java Development Kit from Oracle
  3. You will need a copy of phidget22.jar

Finding Code Samples

To find the code sample to use for your Phidget, navigate to the Code Samples page and select your device from the drop-down menu.

Java sample code.jpg


Once you select your device, the code sample generator will give you a working code sample, and a selection of options to customize it to your needs.

Setting up a New Project

When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget Java library.

To begin, create a new Java project. Give it a name, then click Next >:

Java eclipse linux newproject.PNG


Go to the Libraries tab and click Add External JARs... and add phidget22.jar to your project as an external jar:

Java eclipse linux addjar.PNG


Create a new Class in your project:

Java eclipse linux newClass menu.png


Name the class, and be sure to check the public static void main box.

Java eclipse linux newClass.png


The project now has access to Phidgets.

Using the Code Samples

Now that you have configured a project to use Phidgets, you can copy the code sample from the Code Samples page into your project, and run it.


What's Next?

Now that you have set up Phidgets to work with your programming environment, we recommend you read our guide on Phidget Programming Basics to learn the fundamentals of programming with Phidgets.Next Arrow.png