User:Simpsons contributor/Display window code)

Click on 'edit this page' to copy the source code below

package mandelbrot;

import java.awt.event.*; import java.awt.image.*; import java.awt.*; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*;

public class Window extends JFrame implements ActionListener {   String title = new String("Fractals"); //Autorum variables private double xMin, xMax, yMin, yMax; private int width, height, maxIteration, multiple, run;

//File and image handling private JFileChooser fileChoose = new JFileChooser; private BufferedImage image; //Menus private JMenu fileMenu = new JMenu("File"); private JMenu fractalMenu = new JMenu("Fractals"); //MenuItems private JMenuItem fileMenuSave = new JMenuItem("Save"); private JMenuItem fractalMenuMandelbrotAutoRun = new JMenuItem("Mandelbrot set autorun"); //Menu bars private JMenuBar bar = new JMenuBar; public Window {       //Set up the menus fileMenu.add(fileMenuSave); fractalMenu.add(fractalMenuMandelbrotAutoRun); bar.add(fileMenu); bar.add(fractalMenu); setJMenuBar(bar); //Set the action listeners fileMenuSave.addActionListener(this); fractalMenuMandelbrotAutoRun.addActionListener(this); //Frame setup setLayout(new FlowLayout); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH);       //Will be maximized when open setSize(300, 300); setVisible(true); setTitle(title); repaint; }       public void paint(Graphics g)    { super.paint(g); g.drawImage(image, 5, 54, null); }

public void actionPerformed(ActionEvent e)    { if(e.getSource == fileMenuSave) {           int returnVal = fileChoose.showSaveDialog(Window.this); if (returnVal == JFileChooser.APPROVE_OPTION) {              File outFile = fileChoose.getSelectedFile; try {                  ImageIO.write(image, "png", outFile); } catch (IOException ex) {                  ex.printStackTrace; }           } //End of if loop repaint; }       if(e.getSource == fractalMenuMandelbrotAutoRun) {                       xMin = -0.37465401; xMax = -0.37332411; yMin = 0.659227668; yMax = 0.66020767; width = 1000; height = 1000; maxIteration = 1000; multiple = 2; run = 5; for(int i=1; i<=run; i++) {               title = new String("Mandelbrot autorun " + i + " out of " + run                                    + " (processing...)"); setTitle(title); MandelbrotCreator create = new MandelbrotCreator(width, height, xMin, xMax,                       yMin, yMax, maxIteration, multiple); image = create.image; //Inward zoom xMin = xMin - 0.01; xMax = xMax + 0.01; yMin = yMin - 0.01; yMax = yMax + 0.01; File outFile = new File("C:/Mandel/" + i + ".png"); try {                   ImageIO.write(image, "png", outFile); } catch (IOException ex) {                   ex.printStackTrace; }           }            title = new String("Mandelbrot autorun finished"); setTitle(title); repaint; }   }        }