1
votes

i have been experimenting with the mandelbrot java thing and i seem to be stuck on drawing the image.I used a JFrame and Jpanel to create this. I know the for loops are wrong as I've just been experimenting with it.

public Mandelbrot(){

    JFrame mandelSet = new JFrame("Mandelbrot Set");
    mandelSet.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
    mandelSet.setSize(400,300);
    mandelSet.setVisible(true);
    JPanel picture = new JPanel();
    mandelSet.setContentPane(picture);
    picture.setLayout(new FlowLayout());
    for(int y =0; y<200; y++){
        for(int x=0; x<200; x++){
            while(rx*rx +ix*ix <4 && iteration>0){
                tmp = rx*rx -ix*ix +ry;
                ix = 2.0*rx*ix+iy;
                rx=tmp;
                iteration--;
            }
            I.setRGB(x, y, iteration | iteration <<100);
        }
    }
}
public void paint(Graphics g){
  g.drawImage(I,0,0,this);


}

The draw method seems to be giving me a compilation error. i saw that on the internet but it doesnt seem to work.

1
seems to? does it or doesn't it, and if it does, what is it? :) - 500 - Internal Server Error
it does not work excuse the english - kkk
"Does not work" is not very describing. Neither is "a compilation error". - Werner Kvalem VesterĂ¥s
it shows an error saying mandelbrot cannot be converted to java.awt.imageObserver - kkk
You need to do this in a Applet to be able to use the paint-Method (i assume youre getting a Nullpointer at Runtime rather than compilation error) - JBA

1 Answers

0
votes

You need to have a Applet (e.g. become a Applet by extending from it) to be able to use "that" paint-Method you have in your current source.

I recomend the following procedure to solve your issue:

1.) Read about what a Applet is and how to write a simple HelloWorldApplet

2.) Read about on how to run a Applet from within your IDE (preferably on how to include it into HTML as well so you understand on how they are beeing "deployed" to the client)

3.) Try to implement your logic within the Applet's paint Method (you will no longer experience a NullPointerException because when your paint-Method is called g is initialized).

4.) Take a look at existing examples and/or ask your teacher if you're in class (Here is one: http://www.jjam.de/Java/Applets/Fraktale/Apfelmaennchen_Zoom.html)

Back in my studies I understood everything about the programming part but not about the formula or why its so freaking cool if you visualize it - still think this is one of the coolest things i've ever seen regarding programming ;) I do however understand how confusing the whole thing is when starting (i as well dont think its considered good practise to teach Java or OO by drawing mathematical sh... in an Applet but thats my personal opinion).