Difference between revisions of "Using Eclipse to Write HelloWorld in Java for the Overo"

From Gumstix User Wiki
Jump to: navigation, search
(remove spam)
 
Line 27: Line 27:
 
     }
 
     }
  
Press the green run button to test drive our application on our host machine. You should get something that looks like this:
+
Press the green run button to test drive our application on our host machine.
 
+
[[File:GumstixEclipse12.jpg]]
+
 
+
 
Congratulations! You have now written your first graphical program in Java.
 
Congratulations! You have now written your first graphical program in Java.
  
Line 42: Line 39:
 
:*Choose '''File -> Export''' from the drop down menu
 
:*Choose '''File -> Export''' from the drop down menu
 
:*Choose '''Remote Systems -> Remote File System''' and press '''Next'''
 
:*Choose '''Remote Systems -> Remote File System''' and press '''Next'''
[[File:JavaEclipsePic1.png]]
 
 
:*Expand the drop down for the HelloWorld project
 
:*Expand the drop down for the HelloWorld project
 
::*In the '''bin''' folder choose '''HelloWorld.class'''
 
::*In the '''bin''' folder choose '''HelloWorld.class'''
[[File:JavaEclipsePic5.png]]
 
 
----
 
----
 
Note:
 
Note:
Line 51: Line 46:
 
----
 
----
 
:*For Destination Folder, hit the '''Browse''' button
 
:*For Destination Folder, hit the '''Browse''' button
[[File:JavaEclipsePic2.png]]
 
 
:*In the Browse For Folder window which will appear:
 
:*In the Browse For Folder window which will appear:
 
:*If you have already added a ethernet connection to your Overo COM, it should be in the drop down menu under Local
 
:*If you have already added a ethernet connection to your Overo COM, it should be in the drop down menu under Local
[[File:JavaEclipsePic3.png]]
 
 
:*If it is not, hit '''New'''
 
:*If it is not, hit '''New'''
 
::*Choose '''SSH Only'''
 
::*Choose '''SSH Only'''
 
::*In the '''HOST Name''', put the IP Address
 
::*In the '''HOST Name''', put the IP Address
 
::*Hit Finish
 
::*Hit Finish
[[File:JavaEclipsePic4.png]]
 
 
:*Under '''My Home''' choose '''Desktop''' and hit OK
 
:*Under '''My Home''' choose '''Desktop''' and hit OK
 
:*Back in the Export window, hit '''Finish''' and Eclipse will export your program to your Overo!
 
:*Back in the Export window, hit '''Finish''' and Eclipse will export your program to your Overo!

Latest revision as of 15:52, 1 April 2016

This page will teach you how to create a simple, graphical, java HelloWorld application in Eclipse, export it to you Overo COM, and subsequently run it. This guide assumes that you have already run through Eclipse on Gumstix for new users and have Eclipse installed, and your Gumstix properly connected.

Writing HelloWorld.java in Eclipse

First, you need to write your Java program in Eclipse. This section will show you how to write a small graphical HelloWorld program in Eclipse.

  • Navigate to File-> New-> Java Project
  • Name the project HelloWorld
  • Select "Finish"

Once the project is created,

  • Select File->New->Class
  • Name your class HelloWorld
  • click "Finish"

Add the following code to your class:

   import javax.swing.JFrame;
   import javax.swing.JLabel;
   public class Hello {
   	public static void main(String [] args) {
   		JFrame frame = new JFrame("hello");
   		final JLabel label = new JLabel("hello from Gumstix");
   		frame.getContentPane().add(label);
   		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   		frame.pack();
   		frame.setVisible(true);
   	}
   }

Press the green run button to test drive our application on our host machine. Congratulations! You have now written your first graphical program in Java.


Hint: Eclipse has many auto-completion features. Simply typing /:*<Enter> before a class creates a standard documentation block. Likewise, pressing <Ctrl>+<Space> provides context specific auto-completion options. Many other hints for speedy development are explained in the tutorials here.


Upload your Code onto your Overo COM

Now that you have a graphical program on Eclipse, its time to upload it onto your Overo COM. This will show you how to upload your code onto your Overo COM via ethernet connection. First, you will need to discover to IP Address of your Overo. To do this, see Eclipse on Gumstix for new users: Connect Your Gumstix. Once you have the IP Address of your Gumstix, it is time to export your Java Program onto your Overo COM.

  • Choose File -> Export from the drop down menu
  • Choose Remote Systems -> Remote File System and press Next
  • Expand the drop down for the HelloWorld project
  • In the bin folder choose HelloWorld.class

Note: We want to export the HelloWorld.class file and NOT the HelloWorld.java file. This is because our Overo COM can not compile a .java file. A .class file has already been compiled and is ready to run on a Java Virtual Machine, which our Overo COM will have after some necessary installations.


  • For Destination Folder, hit the Browse button
  • In the Browse For Folder window which will appear:
  • If you have already added a ethernet connection to your Overo COM, it should be in the drop down menu under Local
  • If it is not, hit New
  • Choose SSH Only
  • In the HOST Name, put the IP Address
  • Hit Finish
  • Under My Home choose Desktop and hit OK
  • Back in the Export window, hit Finish and Eclipse will export your program to your Overo!

Installing Necessary Software

Before we can run our program on the Overo COM, there are some opkg we need installed so that we can run a Java Virtual Machine. To do this issue the following commands:

opkg update
opkg install cacao
opkg install classpath-gtk

This installs the Java Library cacao and the GTK which allows you to run graphical JARs.

Next, we need to set our Display to be correct. In the Console window for the Overo COM issue the following command

export DISPLAY=:0.0

This enables the Overo to be able to display onto the monitor correctly. Without setting the display correctly our graphical program will not work.

Running our Program

Now that our Overo COM has the program on it and the necessary software to run it, it is time to run our graphical HelloWorld!


Note: You will need a Monitor connected to your Overo COM to run this program. This does not include the local host.


To do this you first must go into the Remote System Explorer Perspective in Eclipse.

  • From the Window drop down menu, choose Open Perspective -> Other -> Remote System Explorer
  • Find the Overo's IP address
  • Expand (The IP Address) -> My Home -> Desktop -> bin
  • Right click on HelloWorld.class, and choose User Action -> java
  • Hit Enter
  • A Box should appear on your monitor with the text: Hello from Gumstix

Minesweeper

If you wish to move on to something more complex, see the page for Minesweeper in Java. All the code in provided to make a cool, graphically Minesweeper game that can be run on an Overo with a monitor!