Tutorials : Java by Example : Section 1 :
Section One Contents
Basic Graphics Functions
Simple Methods And Basic Data Types
If, Else and Switch: Basic Control Structures

Java Basics

Simple Methods And Basic Data Types - Con't

In this applet you can see how to use variables of type String (for text strings) and type int (for integer numbers, without fractional part). To use numbers for text output, you can simply add the number to the string with a + sign. If you have only a number variable to put out with drawString, you can put empty "" before your number, in order to convert them to a string.

//Sourcecode

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

//Introduces variable output

public class Project3 extends Applet
{
        //We need a global graphics object if
		//we use functions using graphics:
        public Graphics g;

        //This is our method. It's only parameter is
		//the y-coordinate of the text string.
        public void Hallo(int y)
        {
                //str is a variable of type String
                String str="Hallo Java!";
                //our x-coordinate is of type integer
                int x=50;

                g.setColor(Color.black);
                g.drawString(str+" The y-coodinate is: "+y, x, y);
        }

        public void paint (Graphics gr)
        {
                g=gr;

                //We call our method several times
				//with different parameters
                Hallo(50);
                Hallo(100);
                Hallo(150);
                Hallo(200);
                Hallo(250);
        }
}

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.