import java.awt.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
public class Intro extends JPanel {
BufferedImage img = new BufferedImage(800, 400, BufferedImage.TYPE_INT_RGB);
String toPaint = "YMCA";
public final int BREAK_NEVER = 0;
public final int BREAK_CHAR = 1;
public final int BREAK_COUNT = 2;
int neueZeile = 0;
int vertikal = 0;
int horizontal = 0;
int startVertikal = 0;
int modus = 0;
int speed = 100;
char delmiter = 0;
char[] chArRan = null;
char[] chArRight = null;
boolean ignoreWhiteSpace = true;
boolean stop = false;
Color background = null;
Color foreground = null;
Color match = null;
Font searchFont = null;
Font matchFont = null;
public Intro(String str, Color back, Color forg, Color mt, Font sf, Font mf, int vert, int hori, int verS, boolean bln) {
setStandard(str, back, forg, mt, sf, mf, vert, hori, verS, bln);
modus = 0;
}
public Intro(String str, Color back, Color forg, Color mt, Font sf, Font mf, int vert, int hori, int verS, boolean bln, char del) {
setStandard(str, back, forg, mt, sf, mf, vert, hori, verS, bln);
delmiter = del;
modus = 1;
}
public Intro(String str, Color back, Color forg, Color mt, Font sf, Font mf, int vert, int hori, int verS, boolean bln, int nl) {
setStandard(str, back, forg, mt, sf, mf, vert, hori, verS, bln);
neueZeile = nl;
modus = 2;
}
void setStandard(String str, Color back, Color forg, Color mt, Font sf, Font mf, int vert, int hori, int verS, boolean bln) {
setSize(800, 400);
ignoreWhiteSpace = bln;
startVertikal = verS;
vertikal = vert;
horizontal = hori;
searchFont = sf;
matchFont = mf;
background = back;
foreground = forg;
match = mt;
toPaint = str;
chArRan = new char[toPaint.length()];
chArRight = new char[toPaint.length()];
for (int i = 0; i < chArRan.length; i++) {
chArRan[i] = ' ';
chArRight[i] = ' ';
}
}
public void start() {
stop = false;
checkForNotAllowedChars();
chArRan = new char[toPaint.length()];
chArRight = new char[toPaint.length()];
for (int i = 0; i < chArRan.length; i++) {
chArRight[i] = ' ';
goOn(i);
}
repaint();
}
public void stop() {
stop = true;
}
char greatRandomChar() {
int i = (int)(Math.random() * 94) + 32;
return (char)i;
}
void checkForNotAllowedChars() {
char[] ch = toPaint.toCharArray();
int temp = 0;
for (int i = 0; i < ch.length; i++) {
temp = (int)ch[i];
if (temp < 32 || temp > 126) {
ch[i] = '?';
}
}
toPaint = String.valueOf(ch);
}
void goOn(final int element) {
new Thread(new Runnable() {
public void run() {
while (stop == false) {
chArRan[element] = greatRandomChar();
if (chArRan[element] == toPaint.charAt(element)) {
chArRight[element] = chArRan[element];
chArRan[element] = ' ';
break;
}
repaint();
try {
Thread.sleep((int)(Math.random() * speed) + 20);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
repaint();
}
}).start();
}
public void paint(Graphics comp) {
Graphics2D comp2D = img.createGraphics();
int vertikalAkt = startVertikal;
comp2D.setColor(background);
comp2D.fillRect(0, 0, getWidth(), getHeight());
comp2D.setColor(foreground);
comp2D.setFont(searchFont);
for (int i = 0, j = 0; i < chArRan.length; i++, j++) {
if (chArRan[i] != ' ' && (ignoreWhiteSpace == false || toPaint.charAt(i) != ' ')) {
comp2D.drawString(String.valueOf(chArRan[i]), (j + 1) * horizontal, vertikalAkt);
}
if ((modus == 2 && j == neueZeile) || (modus == 1 && delmiter == toPaint.charAt(i))) {
vertikalAkt += vertikal;
j = -1;
}
}
vertikalAkt = startVertikal;
comp2D.setColor(match);
comp2D.setFont(matchFont);
for (int i = 0, j = 0; i < chArRight.length; i++, j++) {
if (chArRight[i] != ' ') {
comp2D.drawString(String.valueOf(chArRight[i]), (j + 1) * horizontal, vertikalAkt);
}
if ((modus == 2 && j == neueZeile) || (modus == 1 && delmiter == toPaint.charAt(i))) {
vertikalAkt += vertikal;
j = -1;
}
}
comp2D.dispose();
comp.drawImage(img, 0, 0, null);
}
public void setString(String str) {
toPaint = str;
}
public String getString() {
return toPaint;
}
public void setForeground(Color col) {
foreground = col;
}
public Color getForeground() {
return foreground;
}
public void setBackground(Color col) {
background = col;
}
public Color getBackground() {
return background;
}
public void setMatch(Color col) {
match = col;
}
public Color getMatch() {
return match;
}
public void setSearchFont(Font f) {
searchFont = f;
}
public Font getSearchFont() {
return searchFont;
}
public void setMatchFont(Font f) {
matchFont = f;
}
public Font getMatchFont() {
return matchFont;
}
public void setVertical(int i) {
vertikal = i;
}
public int getVartical() {
return vertikal;
}
public void setHorizontal(int i) {
horizontal = i;
}
public int getHorizontal() {
return horizontal;
}
public void setVerticalStart(int i) {
startVertikal = i;
}
public int getVerticalStart() {
return startVertikal;
}
public void setIgnoreWhiteSpace(boolean bln) {
ignoreWhiteSpace = bln;
}
public boolean getIgnoreWhiteSpace() {
return ignoreWhiteSpace;
}
public void setDelmiter(char ch) {
delmiter = ch;
}
public char getDelmiter() {
return delmiter;
}
public void setLineBreak(int i) {
neueZeile = i;
}
public int getLineBreak() {
return neueZeile;
}
public void setModus(int i) {
modus = i;
}
public int getModus() {
return modus;
}
public void setSpeed(int i) {
speed = i;
}
public int getSpeed() {
return speed;
}
}