Learning Java Language
The Applete
Samples:
import java.applet.Applet;
import java.awt.*;
public class BlinkingTextApplet extends Applet implements Runnable {
private boolean paintThisTime = false;
private Thread flash = null;
public void start() {
flash = new Thread(this);
flash.start();
}
public void stop() {
flash.stop();
}
public void destroy() {
}
public void paint(Graphics g) {
paintThisTime = !paintThisTime;
if(paintThisTime == false) {
return;
}
g.drawString("Oh!!!No!!!IT BLINKS!!!!!",5,25);
}
public void run() {
while (true) {
try {
flash.sleep(650);
} catch(InterruptedException e) {
}
repaint();
}
}
}
This is how you call this program from the *.html file. This program will blink the
text when run.
<HTML>
<HEAD>
<TITLE>TEST MY JAVA APPLET</TITLE>
</HEAD>
<BODY>
<APPLET CODE="BlinkingTextApplet.class"WIDTH=250 HEIGHT=100>
</APPLET>
</BODY>
</HTML>
The Application Samples:
import java.io.*;
class Console {
static private String GetString(){
try
{
byte bArray[ ] = new byte[128];
System.in.read(bArray);
String s = new String(bArray,0).trim();
return s;
}
catch (IOException ioe)
{
System.out.println(ioe.toString());
ioe.printStackTrace();
return "********";
}
}
static String ReadString() {
String s = GetString();
return s;
}
static String ReadString(String prompt) {
System.out.println(prompt);
return ReadString();
}
static long ReadLong() {
String sl = GetString();
return Long.parseLong(sl);
}
static long ReadLong(String prompt) {
System.out.println(prompt);
return ReadLong();
}
static double ReadDouble() {
String sd = GetString();
return Double.valueOf(sd).doubleValue();
}
static double ReadDouble(String prompt) {
System.out.println(prompt);
return ReadDouble();
}
}
public class ConsoleTest {
public ConsoleTest() {
}
public static void main(String args[]) {
String yesNo = new String("Y");
while (yesNo.equalsIgnoreCase("Y")) {
String s = Console.ReadString("Enter your name: ");
long l = Console.ReadLong("How old are you");
double d = Console.ReadDouble("Balance of your checking account?");
System.out.println(s);
System.out.println(l);
System.out.println(d);
yesNo = Console.ReadString("Do you want to continue (Y/N)?");
do {
}while(true);
}
}
}Jave has brought fundamental change in the Internet technology.
However it has not been that much used on the Internet. One thing Java applets are too
slow because applets need to be downloaded before it runs on the client side. Once it is
there it is normal.
Java Application is very sophisticated and hard to program. It is
very much used in the digital industries for the sophisticated application and highly
advanced chip development such as wireless phone, wireless email computers, etc.
Java language came from SUNMICO (Stanford University Network). Java
has the same syntax and library systems like the C and C++. Also, like C++ it is an object
oriented programming language.
If you know Java and you have
become expert in one of its areas of programming you become in one year millionaire in
America. It is vey hi-tech programming language. Sun Mirco itself is a very
sophisticated digital company in America.
