ich begreif das nicht!
java betruegt mich, ohne spass!
wichtig ist die methode blitz() ab zeile 170.
dort steht eindeutig in zeile 171
[JAVA=171]if(a>10 && a<497 && b>10 && b<497 && grid[a-3] || grid[a+3]){[/code]
sowohl a und b muessaen groesser als 10 sein.
dann schreibt java mir aber spaeter fuer zeile 175:
[JAVA=175]grid[b-2][a]=true;[/code]
ne fehlermeldung die da lautet:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at Lichtenberg.blitz(Lichtenberg.java:175)
at Lichtenberg.randomGuyCrushing(Lichtenberg.java:114)
at Lichtenberg$MalPanel.paint(Lichtenberg.java:76)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:310)
at java.awt.Component.dispatchEventImpl(Component.java:4706)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
was hat das zu bedeuten? ich hab ihm doch gesagt a und b muessen groesser als 10 sein und wenn man dann nur 2 abzieht kanns doch nit -1 werden. ich bin am verzweifeln, bitte helft mir!
java betruegt mich, ohne spass!
Java:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Lichtenberg extends Frame{
Lichtenberg(){
addWindowListener(new MyFinishWindow());
add(new MalPanel());
}
public class MyFinishWindow extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
static int height = 500;
static int pixels = 8000;
static boolean[][] grid = new boolean[height+10][height+10];
Graphics2D g2d;
static int firstDraw = 0;
static int actualPixel;
public void draw(int x, int y){
g2d.drawLine(x,y,x,y);
}
public int random(int max){
double randDoub = Math.random();
int rand = (int)(max*randDoub);
if (rand==max){
System.out.println("WTF!!!!");
rand=0;
}
return rand;
}
public class MalPanel extends Panel{
public void paint(Graphics g){
g2d = (Graphics2D)g;
g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON));
if (firstDraw==0){
g2d.setColor(Color.green);
g2d.fillRect(0,0,height,height);
g2d.setColor(Color.black);
firstDraw++;
}
/*int x = height/2;
int y = height/2;
for (int i=0; i<4; i++){
for (int j=0; j<4; j++){
draw(x-2+i,y-2+j);
grid[x-2+i][y-2+j]=true;
}
}*/
if (firstDraw==1){
for (int i=0; i<=height; i++){
draw(i,0);
grid[i][0]=true;
draw(i,height);
grid[i][height]=true;
draw(0,i);
grid[0][i]=true;
draw(height,i);
grid[height][i]=true;
}
for (actualPixel=0; actualPixel<=pixels; actualPixel++)
randomGuyCrushing();
}
for (int i=0; i<=height; i++){ //nur gegen den fehler
for (int j=0; j<=height; j++){
if (grid[i][j])
draw(i,j);
}
}
}
}
public void randomGuyCrushing(){
int x, y;
do{
x = random(height);
y = random(height);
}while (grid[x][y]);
while(true){
int direction = random(4);
if (direction==0 && y>1){
y--;
}
if (direction==1 && x<height-1){
x++;
}
if (direction==2 && y<height-1){
y++;
}
if (direction==3 && x>1){
x--;
}
if (grid[x][y-1] || grid[x+1][y] || grid[x][y+1] || grid[x-1][y]){
draw(x,y);
grid[x][y] = true;
if (actualPixel<pixels*0.25){
blitz(x,y,3);
}
if (actualPixel<pixels*0.5){
blitz(x,y,2);
}
if (actualPixel<pixels*0.75){
blitz(x,y,1);
}
break;
}
}
}
public void blitz (int b, int a, int n){
int i = 0;
/*while (i<10){
int rand = random(4);
if (rand==0){
if (y>0 && grid[x][y-1]==true){
y--;
i++;
}
}
if (rand==1){
if (x<300 && grid[x+1][y]==true){
x++;
i++;
}
}
if (rand==2){
if (y<300 && grid[x][y+1]==true){
y++;
i++;
}
}
if (rand==3){
if (x>0 && grid[x-1][y]==true){
x--;
i++;
}
}
}*/
while (true){
/*int rand = random(4);
if (rand==0 && y>0)
y--;
if (rand==1 && x<300)
x++;
if (rand==2 && y<300)
y++;
if (rand==3 && x>0)
x--;
if (grid[x][y]==false){
grid[x][y]=true;
break;
}*/
if(n==3){
if(a>10 && a<497 && b>10 && b<497 && grid[b][a-3] || grid[b][a+3]){
grid[b+1][a]=true;
grid[b-1][a]=true;
grid[b+2][a]=true;
grid[b-2][a]=true;
grid[b+3][a]=true;
grid[b-3][a]=true;
}
if(a>3 && a<height-3 && b>3 && b<height-3 && grid[b-3][a] || grid[b+3][a]){
grid[b][a-1]=true;
grid[b][a+1]=true;
grid[b][a-2]=true;
grid[b][a+2]=true;
grid[b][a-3]=true;
grid[b][a+3]=true;
}
}
if(n==2){
if(a>10 && a<height-2 && b>10 && b<height-2 && grid[b][a-2] || grid[b][a+2]){
grid[b+1][a]=true;
grid[b-1][a]=true;
grid[b+2][a]=true;
grid[b-2][a]=true;
}
if(a>2 && a<height-2 && b>2 && b<height-2 && grid[b-2][a] || grid[b+2][a]){
grid[b][a-1]=true;
grid[b][a+1]=true;
grid[b][a-2]=true;
grid[b][a+2]=true;
}
}
if(n==1){
if(a>1 && a<height-1 && b>1 && b<height-1 && grid[b][a-1] || grid[b][a+1]){
grid[b+1][a]=true;
grid[b-1][a]=true;
}
if(a>1 && a<height-1 && b>1 && b<height-1 && grid[b-1][a] || grid[b+1][a]){
grid[b][a-1]=true;
grid[b][a+1]=true;
}
}
break;
}
}
public static void main (String[] args){
Lichtenberg main = new Lichtenberg();
main.setVisible(true);
main.setSize(height+17,height+39);
main.validate();
}
}
wichtig ist die methode blitz() ab zeile 170.
dort steht eindeutig in zeile 171
[JAVA=171]if(a>10 && a<497 && b>10 && b<497 && grid[a-3] || grid[a+3]){[/code]
sowohl a und b muessaen groesser als 10 sein.
dann schreibt java mir aber spaeter fuer zeile 175:
[JAVA=175]grid[b-2][a]=true;[/code]
ne fehlermeldung die da lautet:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at Lichtenberg.blitz(Lichtenberg.java:175)
at Lichtenberg.randomGuyCrushing(Lichtenberg.java:114)
at Lichtenberg$MalPanel.paint(Lichtenberg.java:76)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:310)
at java.awt.Component.dispatchEventImpl(Component.java:4706)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
was hat das zu bedeuten? ich hab ihm doch gesagt a und b muessen groesser als 10 sein und wenn man dann nur 2 abzieht kanns doch nit -1 werden. ich bin am verzweifeln, bitte helft mir!