Click on the images!

// BN 03.02.1999

import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.util.*;

public class Orbit extends java.applet.Applet implements Runnable
{
int nAnzahl = 5;
int nThreadSpeed = 100;
Color BackgroundColor = Color.lightGray;
String BackgroundImageURL = "Back" + ".jpg";
boolean bBackgroundImageMany = true; // Hintegrundbild kacheln
int nBackgroundImageManyDiffX = 0; // nur > 0; links einrücken, wenn Hintergrund von Html und Java abgestimmt werden muß
int nBackgroundImageManyDiffY = 0; // nur > 0; oben einrücken, wenn Hintergrund von Html und Java abgestimmt werden muß

Thread myThread = null;

int nWidth;
int nHeight;
int nFont_x;
int nFont_y;
int nCursor;

Image BackgroundImage = null;
Image Canvas = null;

String ImagesURLs [];
Image Images [];
String ImagesDescription [];
Point ImagesPoints [];
String ImagesLinks [];
String ImagesLinksDescription [];
double ImagesAngle [];
boolean ImagesBackRect [];
boolean bBerech [];
int nImageCurrent = -1;


String sLaufString = "Greetings! Welcome to the new 1999 Cadillac Warehouse" + "\n"
+ " " + "\n"
+ "" + "\n"
+ "a super dealer for a super deal on the Web.Our premise is simple - pick the options, calculate" + "\n"
+ "the cost and compare the awesome savings. There's no sales hassle or pressure. As one of the top Cadillac dealers" + "\n"
+ "in the United States, we assure you superior customer service and satisfaction. From a single mouse click" + "\n"
+ "to delivery of a brand new or pre-owned Cadillac to your front door, the process is fast and easy. Our buying power" + "\n"
+ "is unsurpassed, so we can offer you one of the best deals in the nation - we dare you to compare! " + "\n";
int nLaufStringCounter = 0;
String abc = "";
String abc2 = "";

public void init()
{
// nWidth = this.bounds().width;
// nHeight = this.bounds().height;

if(nWidth == 0){
nWidth = 750;
}
if(nHeight == 0){
nHeight = 600;
}

// nWidth = 800;
// nHeight = 400;

this.resize(nWidth, nHeight);
this.setBackground(BackgroundColor);
this.setFont(new Font("Helvetica", Font.PLAIN, 14));
// this.setFont(new Font("Helvetica", Font.PLAIN, this.getFont().getSize()));
//this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); // erst ab JDK 1.1
nCursor = Cursor.DEFAULT_CURSOR;

abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for(int i = 0; i < abc.length(); i++){
abc2 += abc.substring(0, i) + "\\";
}

Images = new Image [nAnzahl];
ImagesPoints = new Point [nAnzahl];
ImagesDescription = new String [nAnzahl];
ImagesURLs = new String [nAnzahl];
ImagesLinks = new String [nAnzahl];
ImagesLinksDescription = new String [nAnzahl];
ImagesAngle = new double [nAnzahl];
ImagesBackRect = new boolean[nAnzahl];
bBerech = new boolean[nAnzahl];


for(int i = 0; i < nAnzahl; i++){
switch(i){
case 0:
// ändern
ImagesURLs[i] = "1.jpg";
ImagesPoints[i] = new Point(1 * 120, 1 * 150);
ImagesLinks[i] = "Cadillac_blue.html";
ImagesLinksDescription[i] = "Cadillac blue";
ImagesAngle[i] = 3;
ImagesBackRect[i] = true;
bBerech[i] = true;
ImagesDescription[i] = "";
//
Images[i] = null;
break;
case 1:
// ändern
ImagesURLs[i] = "2.jpg";
ImagesPoints[i] = new Point(1 * 120, 2 * 150);
ImagesLinks[i] = "Jukebox.html";
ImagesLinksDescription[i] = "Jukebox";
ImagesAngle[i] = 2;
ImagesBackRect[i] = true;
bBerech[i] = true;
ImagesDescription[i] = "";
//
Images[i] = null;
break;
case 2:
// ändern
ImagesURLs[i] = "3.jpg";
ImagesPoints[i] = new Point(-10, 2 * 150);
ImagesLinks[i] = "Cadillac_yellow.html";
ImagesLinksDescription[i] = "Cadillac yellow";
ImagesAngle[i] = 3;
ImagesBackRect[i] = true;
bBerech[i] = true;
ImagesDescription[i] = "";
//
Images[i] = null;
break;
case 3:
// ändern
ImagesURLs[i] = "4.jpg";
ImagesPoints[i] = new Point(2 * 120, 1 * 150);
ImagesLinks[i] = "Cadillac_red.html";
ImagesLinksDescription[i] = "Cadillac red";
ImagesAngle[i] = 2;
ImagesBackRect[i] = true;
bBerech[i] = true;
ImagesDescription[i] = "";
//
Images[i] = null;
break;
case 4:
// ändern
ImagesURLs[i] = "5.jpg";
ImagesPoints[i] = new Point(2 * 120, 2 * 150);
ImagesLinks[i] = "Cadillac_black.html";
ImagesLinksDescription[i] = "Cadillac black";
ImagesAngle[i] = 2;
ImagesBackRect[i] = true;
bBerech[i] = true;
ImagesDescription[i] = "";
//
Images[i] = null;
break;
}
}
}

public void start() {
if(myThread == null){
myThread = new Thread(this);
myThread.start();
}
}

public void stop() {
myThread = null;
}

public void run() {
int i = 0;

while (myThread != null){
try {
Thread.sleep(nThreadSpeed);
} catch (InterruptedException e){
}
repaint();
i++;
if(i >= nThreadSpeed / 20){
i = 0;
berechnen();
}
}
myThread = null;
}

public void update(Graphics g)
{
paint(g);
}

public void paint(Graphics g)
{
if(BackgroundImageURL.length() > 0 && BackgroundImage == null){
try {
Image Imag = this.getImage(new URL(this.getCodeBase() + BackgroundImageURL));
if(Imag != null){
BackgroundImage = this.createImage(nWidth, nHeight);

MediaTracker Media = new MediaTracker(this);
Media.addImage(Imag, 0);
try {
Media.waitForID(0);
} catch (InterruptedException e) {
}
if(BackgroundImage != null){
Graphics g2 = BackgroundImage.getGraphics();
if(bBackgroundImageMany == false){
g2.drawImage(Imag, 0, 0, nWidth, nHeight, null); // Zoom
} else if(bBackgroundImageMany == true){
for(int y = 0; y < (1 + nHeight / Imag.getHeight(null) + (nBackgroundImageManyDiffY / Imag.getHeight(null))); y++){
for(int x = 0; x < (1 + nWidth / Imag.getWidth(null) + (nBackgroundImageManyDiffX / Imag.getWidth(null))); x++){
g2.drawImage(Imag, x * Imag.getWidth(null) - nBackgroundImageManyDiffX, y * Imag.getHeight(null) - nBackgroundImageManyDiffY, Imag.getWidth(null), Imag.getHeight(null), null); // Many
}
}
}
/*
// Filter anwenden
{
ImageFilter f = new GrayFilter();
BackgroundImage = this.createImage(new FilteredImageSource(BackgroundImage.getSource(), f));
}
//
*/
}
}
} catch (java.net.MalformedURLException e){
}
}
if(Canvas == null){
Canvas = createImage(nWidth, nHeight);
}
if(Canvas != null){
Graphics g2 = Canvas.getGraphics();

g2.setColor(this.getBackground());
g2.fillRect(0, 0, nWidth, nHeight);

if(BackgroundImageURL.length() > 0 && BackgroundImage != null){
g2.drawImage(BackgroundImage, 0, 0, BackgroundImage.getWidth(null), BackgroundImage.getHeight(null), null);
}

// sLaufString
if(sLaufString.length() > 0){
int x = 100;
int y = 100;

nLaufStringCounter++;
if(nLaufStringCounter > sLaufString.length()){
nLaufStringCounter = 0;
}
String Stri = sLaufString.substring(0, nLaufStringCounter);
{
int nFontHeight = (this.getFontMetrics(g2.getFont()).getHeight()) + 1;

g2.setColor(Color.black);
int nCounter = 1;
StringTokenizer StringToken = new StringTokenizer(Stri, "\n");
while(StringToken.hasMoreTokens() == true){
String sStri = StringToken.nextToken();
printStringBunt(g2, sStri, 0 + 12, 12 + (nCounter * nFontHeight));
// printStringBunt(g2, sStri, x + 2, y + (nCounter * nFontHeight));
// g2.drawString(sStri, x + 2, y + (nCounter * nFontHeight));
nCounter++;
}
}
}


// Image
for(int i = 0; i < nAnzahl; i++){
if(Images[i] == null){
try {
Images[i] = this.getImage(new URL(this.getCodeBase() + ImagesURLs[i]));

MediaTracker Media = new MediaTracker(this);
Media.addImage(Images[i], 0);
try {
Media.waitForID(0);
} catch (InterruptedException e) {
}
} catch (java.net.MalformedURLException e){
}
}
if(Images[i] != null){
if(ImagesBackRect[i] == true){
g2.setColor(Color.black);
g2.drawRect(getCoor(ImagesPoints[i], i).x - 1, getCoor(ImagesPoints[i], i).y - 1, Images[i].getWidth(null), Images[i].getHeight(null));
g2.setColor(Color.white);
g2.drawRect(getCoor(ImagesPoints[i], i).x, getCoor(ImagesPoints[i], i).y, Images[i].getWidth(null), Images[i].getHeight(null));
}
g2.drawImage(Images[i], getCoor(ImagesPoints[i], i).x, getCoor(ImagesPoints[i], i).y, null);
}

}

// Description
for(int i = 0; i < nAnzahl; i++){
if(Images[i] != null){

nImageCurrent = - 1;
for(int z = 0; z < nAnzahl; z++){
if(Images[z] != null){
int x1 = getCoor(ImagesPoints[z], z).x;
int y1 = getCoor(ImagesPoints[z], z).y;
int x2 = x1 + Images[z].getWidth(null);
int y2 = y1 + Images[z].getHeight(null);
if((nFont_x >= x1 && nFont_x <= x2) && (nFont_y >= y1 && nFont_y <= y2)){
nImageCurrent = z;
}
}
}

}
if(nImageCurrent == i){
if(ImagesLinksDescription[i].length() > 0){
int nFontWidth;
int nFontHeight;
int x;
int y;

nFontWidth = (this.getFontMetrics(g2.getFont()).stringWidth(ImagesLinksDescription[i]));
nFontHeight = (this.getFontMetrics(g2.getFont()).getHeight()) + 1;

x = nFont_x;
y = nFont_y + nFontHeight + 5;
if((x + nFontWidth + 2 + 2) > nWidth){
x = nWidth - (nFontWidth + 2 + 2);
}
if((y + nFontHeight + 5 + 2) > nHeight){
y = nHeight - (nFontHeight + 5 + 2);
}

g2.setColor(Color.orange);
g2.fillRect(x, y, nFontWidth + 2, nFontHeight);
g2.setColor(Color.black);
g2.drawRect(x, y, nFontWidth + 2, nFontHeight);

g2.drawString(ImagesLinksDescription[i], x + 2, y + nFontHeight - 3);
}
}
}

// Text
for(int i = 0; i < nAnzahl; i++){
if(nImageCurrent == i){
if(Images[i] != null){
if(ImagesDescription[i].length() > 0){
int nFontWidthMax = 0;
int nFontHeightMax = 0;
int nFontWidth;
int nFontHeight;
int x;
int y;

{
StringTokenizer StringToken = new StringTokenizer(ImagesDescription[i], "\n");
while(StringToken.hasMoreTokens() == true){
String sStri = StringToken.nextToken();

int nWert = (this.getFontMetrics(g2.getFont()).stringWidth(sStri));
if(nWert > nFontWidthMax){
nFontWidthMax = (this.getFontMetrics(g2.getFont()).stringWidth(sStri)) + 1;
}
nFontHeightMax++;
}
}
nFontHeight = (this.getFontMetrics(g2.getFont()).getHeight()) + 1;
nFontHeightMax *= nFontHeight + 1;

x = nFont_x;
y = nFont_y + (3 * nFontHeight);
if((x + nFontWidthMax + 2 + 2) > nWidth){
x = nWidth - (nFontWidthMax + 2 + 2);
}
if((y + nFontHeightMax + (0 * nFontHeight) + 2) > nHeight){
y = nHeight - (nFontHeightMax + (0 * nFontHeight) + 2);
}

g2.setColor(Color.yellow);
g2.fillRect(x, y, nFontWidthMax + 2, nFontHeightMax);
g2.setColor(Color.black);
g2.drawRect(x, y, nFontWidthMax + 2, nFontHeightMax);

g2.setColor(Color.black);
int nCounter = 1;
StringTokenizer StringToken = new StringTokenizer(ImagesDescription[i], "\n");
while(StringToken.hasMoreTokens() == true){
String sStri = StringToken.nextToken();
g2.drawString(sStri, x + 2, y + (nCounter * nFontHeight));
// g2.drawString(sStri, x + 2, nFont_y + (nCounter * nFontHeight));
nCounter++;
}
}
}
}
}
if(nImageCurrent == -1){
if(nCursor != Cursor.DEFAULT_CURSOR){
//this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); // erst ab JDK 1.1
nCursor = Cursor.DEFAULT_CURSOR;
}
} else {
if(nCursor != Cursor.HAND_CURSOR){
//this.setCursor(new Cursor(Cursor.HAND_CURSOR)); // erst ab JDK 1.1
nCursor = Cursor.HAND_CURSOR;
}
}

g.drawImage(Canvas, 0, 0, null);
}
}

public void printStringBunt(Graphics g2, String sStri, int nWert_x, int nWert_y)
{
int x = 0;

g2.setColor(Color.black);
StringTokenizer StringToken = new StringTokenizer(sStri, abc2, true);
while(StringToken.hasMoreTokens() == true){
String sStr = StringToken.nextToken();
//Color Col = g2.getColor();
//g2.setColor(Col.brighter());
// g2.setColor(g2.getColor().brighter());

/*
if(sStr.compareTo("A") == 0){
g2.setColor(Color.red);
} else if(sStr.compareTo("B") == 0){
g2.setColor(Color.green);
} else if(sStr.compareTo("C") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("D") == 0){
g2.setColor(Color.yellow);
} else if(sStr.compareTo("E") == 0){
g2.setColor(Color.orange);
} else if(sStr.compareTo("F") == 0){
g2.setColor(Color.gray);
} else if(sStr.compareTo("G") == 0){
g2.setColor(Color.white);
} else if(sStr.compareTo("H") == 0){
g2.setColor(Color.lightGray);
} else if(sStr.compareTo("I") == 0){
g2.setColor(Color.cyan);
} else if(sStr.compareTo("J") == 0){
g2.setColor(Color.black);
} else if(sStr.compareTo("K") == 0){
g2.setColor(Color.magenta);
} else if(sStr.compareTo("L") == 0){
g2.setColor(Color.cyan);
} else if(sStr.compareTo("M") == 0){
g2.setColor(Color.red);
} else if(sStr.compareTo("N") == 0){
g2.setColor(Color.red);
} else if(sStr.compareTo("O") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("P") == 0){
g2.setColor(Color.black);
} else if(sStr.compareTo("Q") == 0){
g2.setColor(Color.green);
} else if(sStr.compareTo("R") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("S") == 0){
g2.setColor(Color.magenta);
} else if(sStr.compareTo("T") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("U") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("V") == 0){
g2.setColor(Color.yellow);
} else if(sStr.compareTo("W") == 0){
g2.setColor(Color.gray);
} else if(sStr.compareTo("X") == 0){
g2.setColor(Color.lightGray);
} else if(sStr.compareTo("Y") == 0){
g2.setColor(Color.orange);
} else if(sStr.compareTo("Z") == 0){
g2.setColor(Color.blue);

} else if(sStr.compareTo("a") == 0){
g2.setColor(Color.red);
} else if(sStr.compareTo("b") == 0){
g2.setColor(Color.green);
} else if(sStr.compareTo("c") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("d") == 0){
g2.setColor(Color.white);
} else if(sStr.compareTo("e") == 0){
g2.setColor(Color.black);
} else if(sStr.compareTo("f") == 0){
g2.setColor(Color.yellow);
} else if(sStr.compareTo("g") == 0){
g2.setColor(Color.orange);
} else if(sStr.compareTo("h") == 0){
g2.setColor(Color.cyan);
} else if(sStr.compareTo("i") == 0){
g2.setColor(Color.magenta);
} else if(sStr.compareTo("j") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("k") == 0){
g2.setColor(Color.red);
} else if(sStr.compareTo("l") == 0){
g2.setColor(Color.green);
} else if(sStr.compareTo("m") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("n") == 0){
g2.setColor(Color.white);
} else if(sStr.compareTo("o") == 0){
g2.setColor(Color.black);
} else if(sStr.compareTo("p") == 0){
g2.setColor(Color.red);
} else if(sStr.compareTo("q") == 0){
g2.setColor(Color.green);
} else if(sStr.compareTo("r") == 0){
g2.setColor(Color.orange);
} else if(sStr.compareTo("s") == 0){
g2.setColor(Color.yellow);
} else if(sStr.compareTo("t") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("u") == 0){
g2.setColor(Color.black);
} else if(sStr.compareTo("v") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("w") == 0){
g2.setColor(Color.green);
} else if(sStr.compareTo("x") == 0){
g2.setColor(Color.blue);
} else if(sStr.compareTo("y") == 0){
g2.setColor(Color.red);
} else if(sStr.compareTo("z") == 0){
g2.setColor(Color.blue);
} else {
g2.setColor(Color.black);
}
*/
// Cadillac
if(sStr.compareTo("C") == 0){
g2.setColor(new Color(90 + 0, 0, 0));
} else if(sStr.compareTo("a") == 0){
g2.setColor(new Color(100 + 0, 0, 0));
} else if(sStr.compareTo("d") == 0){
g2.setColor(new Color(100 + 10, 0, 0));
} else if(sStr.compareTo("i") == 0){
g2.setColor(new Color(100 + 20, 0, 0));
} else if(sStr.compareTo("l") == 0){
g2.setColor(new Color(100 + 30, 0, 0));
} else if(sStr.compareTo("a") == 0){
g2.setColor(new Color(100 + 40, 0, 0));
} else if(sStr.compareTo("c") == 0){
g2.setColor(new Color(100 + 50, 0, 0));
} else {
g2.setColor(new Color(100 + 50, 0, 0));
}

g2.drawString(sStr, nWert_x + x, nWert_y);
x += (this.getFontMetrics(g2.getFont()).stringWidth(sStr));
}
}

public Point getCoor(Point P, int i){
// return new Point((P.x) + nWidth / 2 - Images[i].getWidth(null) / 2, (P.y) + nHeight / 2 - Images[i].getHeight(null) / 2);
return new Point((P.x + nWidth / 4), (P.y + nHeight / 4));
}

public void berechnen(){
double GRAD_PI = 180 * Math.PI;

for(int i = 0; i < nAnzahl; i++){
if(Images[i] != null){
if(bBerech[i] == true){

double x = this.ImagesPoints[i].x - Images[i].getWidth(null) / 2;
double y = this.ImagesPoints[i].y - Images[i].getHeight(null) / 2;

double dAngle = this.ImagesAngle[i];
double dx = Math.cos(dAngle / GRAD_PI) * x - Math.sin(dAngle / GRAD_PI) * y;
double dy = Math.sin(dAngle / GRAD_PI) * x + Math.cos(dAngle / GRAD_PI) * y;
this.ImagesPoints[i].x = (int) (Math.round(dx)) + Images[i].getWidth(null) / 2;
this.ImagesPoints[i].y = (int) (Math.round(dy)) + Images[i].getHeight(null) / 2;

if(this.ImagesPoints[i].x > nWidth / 4 || this.ImagesPoints[i].x < -nWidth / 4){
this.ImagesAngle[i] *= -1;
}
if(this.ImagesPoints[i].y > nHeight / 4 || this.ImagesPoints[i].y < -nHeight / 4){
this.ImagesAngle[i] *= -1;
}

}
}
}
}

public boolean mouseDown(Event evt, int x, int y)
{
nFont_x = x;
nFont_y = y;
for(int i = 0; i < nAnzahl; i++){
if(Images[i] != null){
int x1 = getCoor(ImagesPoints[i], i).x;
int y1 = getCoor(ImagesPoints[i], i).y;
int x2 = x1 + Images[i].getWidth(null);
int y2 = y1 + Images[i].getHeight(null);
if((x >= x1 && x <= x2) && (y >= y1 && y <= y2)){
if(evt.controlDown() == false){
// Action
try {
this.getAppletContext().showDocument(new URL(this.getCodeBase() + ImagesLinks[i]));
} catch (java.net.MalformedURLException e){
}
}
nFont_x = x;
nFont_y = y;
nImageCurrent = -1;
}
}
}

return true;
}

public boolean mouseUp(Event evt, int x, int y)
{
for(int i = 0; i < nAnzahl; i++){
bBerech[i] = true;
}
nFont_x = x;
nFont_y = y;
for(int i = 0; i < nAnzahl; i++){
if(Images[i] != null){
int x1 = getCoor(ImagesPoints[i], i).x;
int y1 = getCoor(ImagesPoints[i], i).y;
int x2 = x1 + Images[i].getWidth(null);
int y2 = y1 + Images[i].getHeight(null);
if((x >= x1 && x <= x2) && (y >= y1 && y <= y2)){
nImageCurrent = i;
nFont_x = x;
nFont_y = y;
}
}
}
return true;
}

public boolean mouseMove(Event evt, int x, int y)
{
nFont_x = x;
nFont_y = y;
for(int i = 0; i < nAnzahl; i++){
if(Images[i] != null){
int x1 = getCoor(ImagesPoints[i], i).x;
int y1 = getCoor(ImagesPoints[i], i).y;
int x2 = x1 + Images[i].getWidth(null);
int y2 = y1 + Images[i].getHeight(null);
if((x >= x1 && x <= x2) && (y >= y1 && y <= y2)){
nImageCurrent = i;
nFont_x = x;
nFont_y = y;
}
}
}
return true;
}

public boolean mouseDrag(Event evt, int x, int y)
{
for(int i = 0; i < nAnzahl; i++){
if(Images[i] != null){
int x1 = getCoor(ImagesPoints[i], i).x;
int y1 = getCoor(ImagesPoints[i], i).y;
int x2 = x1 + Images[i].getWidth(null);
int y2 = y1 + Images[i].getHeight(null);
if((x >= x1 && x <= x2) && (y >= y1 && y <= y2)){
this.ImagesPoints[i].x = x - (nWidth / 4) - Images[i].getWidth(null) / 2;
this.ImagesPoints[i].y = y - (nHeight / 4) - Images[i].getHeight(null) / 2;
bBerech[i] = false;
}
}
}
return true;
}
}

class GrayFilter extends RGBImageFilter
{
int nHelligkeit = 100;

public GrayFilter()
{
canFilterIndexColorModel = true;
}

public int filterRGB(int x, int y, int rgb)
{
if(nHelligkeit == 0){
nHelligkeit = 100;
}
int a = (rgb & 0xFF000000);
int r = ((rgb & 0xFF0000) * nHelligkeit) / 100;
int g = ((rgb & 0x00FF00) * nHelligkeit) / 100;
int b = ((rgb & 0x0000FF) * nHelligkeit) / 100;

return a | r | g | b;
}
}