-1

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.

Jake
  • 328
  • 2
  • 14
kkk
  • 33
  • 5
  • seems to? does it or doesn't it, and if it does, what is it? :) – 500 - Internal Server Error Mar 12 '15 at 11:54
  • it does not work excuse the english – kkk Mar 12 '15 at 12:02
  • "Does not work" is not very describing. Neither is "a compilation error". – Werner Kvalem Vesterås Mar 12 '15 at 12:06
  • it shows an error saying mandelbrot cannot be converted to java.awt.imageObserver – kkk Mar 12 '15 at 12:10
  • 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 Mar 12 '15 at 12:10
  • @JBA yes i am. so how would i be able to paint the image if i can't use the paint method – kkk Mar 12 '15 at 12:13
  • @Spectrambanweezy I made you a answer based on the assumptation you are expected to implement it as a Applet - if you want to implement it as a Swing based standalone application you would need to do a lot more (like refreshing and so on) that is currently handlet by the Applet (and its anchestors). – JBA Mar 12 '15 at 12:20

1 Answers1

0

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).

JBA
  • 2,769
  • 5
  • 24
  • 40