Getting your first program running

Applet, Application, MIDlet, Servlet, JSP
cit.KarlGrabe.com updated 27 Jan 2014


Lab Excercises to do but first get started with your first program:

Links on this page: Other Links:

 

 



How to get your first Applet running with BlueJ

Start BlueJ

  1. Close previous projects
  2. Project | New Project
  3. Click New Class button
  4. Name class. myApplet
  5. Double click on the myApplet rectangle that was just created
  6. Delete all of the code and replace with the following:

    import java.awt.*;
    import java.applet.*;

    public class myApplet extends Applet {
    public void paint (Graphics g) {
    g.drawString ("first CIT java applet", 10,10);
    }
    }

  7. Check that the class name "myApplet" matches the name you created in step 4. If not change the class name in the code you pasted in step 6.
  8. Click Compile button to check for any errors. Close window.
  9. Right-Click on myApplet rectange and select Run Applet.
  10. Select Run Applet in Applet Viewer
  11. You should see an applet view window open and have the text "first CIT java applet" displayed.

How to get your first Application running with BlueJ

Start BlueJ

  1. Close previous projects
  2. Project | New Project
  3. Click New Class button
  4. Name class e.g. myAplication
  5. Double click on the myApplication rectangle that was just created
  6. Code your application or delete everything and paste in an example from the noted.
  7. Make sure the class name and file name match (class must be called myApplication)
  8. Click Compile button to check for any errors. Close window.
  9. Right-Click on myApplicatin rectange and select void main ( )
  10. Click OK at the next dialog (no need to enter anything)
  11. Your application should run, if you can't see it check it is not hidden behind some other windows.

How to get your first Applet running with Eclipse

File - New - Project...
Java project - Next
Enter Project Name
Finish

New - Class
Enter class name in text field labellled Name:
Do not check public static void main ( )
Finish

Add this to the top of the file (before the class definition
import java.awt.*;
import java.applet.*;

Now add a paint method in the class body and extend class from Applet:
public class myApplet2Class extends Applet {
public void paint (Graphics g){
g.drawString("hello there", 10, 10);
}
}

Click green Run and select Run as
Select Java Applet -


How to get your first Application running with Eclipse

File - New - Project...
Java project - Next
Enter Project Name
Finish

Now add a class file and code a main method
New - Class
Enter class name in text field labellled Name:
Create main mehtod should be checked
Finish
In main method enter code:
System.out.println("hello there");

click green run button
Select Java Application, right click select new
Click Run
Save & Launch dialog - click OK


How to get your first Applet running using NetBeans 7

Create a new Project

 

In the Name and Location dialog:

Now Create an Applet class

Name and Location

To run

Some code to try

import java.awt.*;
import java.applet.*;

public class myApplet extends Applet {
public void paint (Graphics g) {
g.drawString ("first CIT java applet", 10,10);
}
}

you can now add more lines after g.drawStrin... above - look up the Graphics class in the API


How to get your first Application running using NetBeans 7

Create a new Project

 

In the Name and Location dialog:

Create an application class


To run
Some code to try
System.out.println ("hello");

Run again - "hello" will appear in the Output window



How to get your a GUI Application running using NetBeans 7

Name and Location


How to get your first MIDlet (moble phone application) running using NetBeans 5.5/6

Create a new Project

 

In the Name and Location dialog:

Select Default (Mobile) platform:

More Configurations

Create a source MIDlet java file:

 

Name and Location Dialog

 

You should see the HelloCIT default code, but it does nothing so...

 

Run the MIDlet in the phone emulator

Make some changes and run it again


How to get a Netbeans MIDlet up and running on a YOUR (real) phone


How to get your first MIDlet (moble phone application) running using Eclipse
  
  1.             J2ME | J2ME Midlet
  2.             Next
  3.             Name your class
  4.             Next
  5.             Finish
   

 


cit.KarlGrabe.com