aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes mandelbrot casse tete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "mandelbrot casse tete" Watch "mandelbrot casse tete" New topic
Author

mandelbrot casse tete

luc ndabaneze
Greenhorn

Joined: May 06, 2003
Posts: 26
hello there
i have been trying to produce a mandelbrot set java apps
and i keep banging my head to the wall
can anybody tell me what is wrong with my code?

import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import javax.swing.*;




public class display extends JFrame {


public display(){
setTitle("MandelbrotSet");
setSize(300,300);
setBackground(Color.white);
mandelbrot mandel;
getContentPane().setLayout(new BorderLayout() );
JPanel Bottom = new JPanel();
JButton StartButton = new JButton("START");
StartButton.setEnabled(true);
mandel= new mandelbrot();
getContentPane().add(mandel , BorderLayout.CENTER);
//Thread t = new Thread(mandel);
//t.start();
StartButton.addActionListener(mandel);
Bottom.add(StartButton);
getContentPane().add(Bottom,BorderLayout.SOUTH);


}
class Complex {
double real,imag ;

Complex() {
real= 0.0;
imag= 0.0;
}
Complex(double x, double y) {

real= x;
imag= y;
}
double length(Complex z){
return (z.real*z.imag);
}
};



class mandelbrot extends JPanel implements Runnable,ActionListener {

Graphics offscreen ;
Image im;
// offscreen = im.getGraphics();
Thread runner ;

double xscale,yscale;
double xmin = -2;
double xmax = 2.5;
double ymin = -2;
double ymax = 2.5;
int width =300; //getSize().width;
int height = 300;//getSize().height;


//private int width = 300;
//private int height = 300;
Complex z = new Complex();
public void actionPerformed(ActionEvent event){
String command = event.getActionCommand();
if (command.equals("START")) {
startRunning();
}
}
void startRunning() {
//coloredCoordinates();
//update(offscreen);}
runner = new Thread(this);
runner.start();
}


public void paint(Graphics g) {
if (im == null) {

g.setColor(Color.blue);
g.fillRect(0,0,getWidth(),getHeight());
}
else {
g.drawImage(im,0,0,null);
}


}


int caliter(){

Complex c;
c= new Complex(0,0);
z.real= c.real;
z.imag= c.imag;
int count;
count=0;

while (count< 256 && z.length(z)<4) {
z.real= (z.real*z.real) - (z.imag*z.imag) + c.real;
z.imag = 2*(z.real*z.imag)+ c.imag;
c.real=z.real;
c.imag= z.imag;
}
count++;
return count;
}

void coloredCoordinates(){
//int width = getSize().width;
//int height = getSize().height;

xscale= (xmax - xmin)/width;
yscale = (ymax - ymin)/height;


for (int x = 0 ;x<width;x++) {
x=(int)(xmin+ (x*xscale)) ;
for (int y =0 ; y<height;y++) {

y= (int)(ymin + (y*yscale));
int index = caliter();

setPixel(offscreen ,x,y,index);
}
}
}

void setPixel( Graphics g,int x, int y,int colour) {

g.setColor(Color.getHSBColor(colour,0f,1f));

g.fillRect( x, y, 1,1);

}


public void run()
{
//int width = getSize().width;
//int height = getSize().height;
Image im = createImage(width,height);
offscreen = im.getGraphics();

offscreen.setColor(Color.white);
offscreen.fillRect(0,0,width,height);


coloredCoordinates();

repaint();


}
}

public static void main (String[] args) {

try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());


catch (Exception e) {}

display application = new display();
application.show();

application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE) ;

}
}


i'd appreciate


There was a young man of Cadiz <br />Who inferred that life is what it is , <br />for he early learnt ,<br /> If it were what it weren't ,<br />it could not be that which it is
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mandelbrot casse tete