Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to complete a java application that shows orbital fractals with two diffe

ID: 3546744 • Letter: I

Question

I need to complete a java application that shows orbital fractals with two different colors.  Below are directions:


This is the first part of a two-part project.

You will be working on an applet/application that draws a family of orbital fractals. (Orbital fractals are formed by using a function that repeatedly moves a point from place to place, and plotting a dot at each successive location of that point.)

Your first task is to complete the GUI by adding the appropriate Swing components and listener functors to duplicate the appearance and behavior of the sample solution (orbitalgui.jar) (There may be minor differences on differnet operating systems.)

Some notes:

Explanation / Answer

IntegerInput.java


import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.*;

public class IntegerInput extends JPanel
{

    private JTextField intIn;

    public IntegerInput(String s, int initialValue, int width)
    {
        setBackground(Color.lightGray);
        add(new JLabel(s));
        intIn = new JTextField((new StringBuilder()).append("").append(initialValue).toString(), width);
        add(intIn);
    }

    public int getInt()
    {
        int i = 0;
        try
        {
            Integer integer = new Integer(intIn.getText());
            i = integer.intValue();
        }
        catch(Exception exception) { }
        return i;
    }

    public void setValue(int i)
    {
        intIn.setText((new StringBuilder()).append("").append(i).toString());
        intIn.repaint();
    }

    public void addActionListener(ActionListener actionlistener)
    {
        intIn.addActionListener(actionlistener);
    }

    public void removeActionListener(ActionListener actionlistener)
    {
        intIn.removeActionListener(actionlistener);
    }
}


Orbital.java


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

public class Orbital extends JPanel
{

    private Color color1;
    private Color color2;
    private int a;
    private int b;
    private int c;
    private int d;
    private JPanel canvas;
    private Image buffer;
    private JButton colorChooser1;
    private JButton colorChooser2;
    private IntegerInput aIn;
    private IntegerInput bIn;
    private IntegerInput cIn;
    private IntegerInput nDots;
    private JPanel self;

    public Orbital()
    {
        color1 = Color.red;
        color2 = Color.blue;
        a = 34;
        b = 1;
        c = 5;
        d = 65;
        buffer = null;
        self = this;
    }

    public void init()
    {
        setLayout(new BorderLayout());
        canvas = new JPanel() {

            final Orbital a;

            public void paint(Graphics g)
            {
                if(Orbital._mthchar(a) != null)
                {
                    g.drawImage(Orbital._mthchar(a), 0, 0, this);
                }
            }

           
            {
                a = Orbital.this;
               
            }
        };
        canvas.setBackground(Color.white);
        canvas.setPreferredSize(new Dimension(400, 400));
        add(canvas, "Center");
        JPanel jpanel = new JPanel();
        colorChooser1 = new JButton("Color 1");
        colorChooser1.setForeground(color1);
        jpanel.add(colorChooser1);
        colorChooser1.addActionListener(new ActionListener() {

            final Orbital a;

            public void actionPerformed(ActionEvent actionevent)
            {
                try
                {
                    Orbital._mthif(a, JColorChooser.showDialog(Orbital._mthdo(a), "Color 1", Orbital._mthgoto(a)));
                }
                catch(Exception exception) { }
                Orbital._mthfor(a).setForeground(Orbital._mthgoto(a));
                Orbital._mthtry(a);
            }

           
            {
                a = Orbital.this;
               
            }
        });
        colorChooser2 = new JButton("Color 2");
        colorChooser2.setForeground(color2);
        jpanel.add(colorChooser2);
        colorChooser2.addActionListener(new ActionListener() {

            final Orbital a;

            public void actionPerformed(ActionEvent actionevent)
            {
                try
                {
                    Orbital.a(a, JColorChooser.showDialog(Orbital._mthdo(a), "Color 2", Orbital.a(a)));
                }
                catch(Exception exception) { }
                Orbital._mthelse(a).setForeground(Orbital.a(a));
                Orbital._mthtry(a);
            }

           
            {
                a = Orbital.this;
               
            }
        });
        aIn = new IntegerInput("a:", a, 3);
        aIn.addActionListener(new ActionListener() {

            final Orbital a;

            public void actionPerformed(ActionEvent actionevent)
            {
                int i = Orbital._mthnew(a);
                try
                {
                    Orbital._mthif(a, Orbital._mthint(a).getInt());
                    if(Orbital._mthnew(a) != i)
                    {
                        Orbital._mthtry(a);
                    }
                }
                catch(Exception exception) { }
            }

           
            {
                a = Orbital.this;
               
            }
        });
        jpanel.add(aIn);
        bIn = new IntegerInput("b:", b, 3);
        bIn.addActionListener(new ActionListener() {

            final Orbital a;

            public void actionPerformed(ActionEvent actionevent)
            {
                int i = Orbital._mthvoid(a);
                try
                {
                    Orbital._mthdo(a, Orbital._mthlong(a).getInt());
                    if(Orbital._mthvoid(a) != i)
                    {
                        Orbital._mthtry(a);
                    }
                }
                catch(Exception exception) { }
            }

           
            {
                a = Orbital.this;
               
            }
        });
        jpanel.add(bIn);
        cIn = new IntegerInput("c:", c, 3);
        cIn.addActionListener(new ActionListener() {

            final Orbital a;

            public void actionPerformed(ActionEvent actionevent)
            {
                int i = Orbital._mthif(a);
                try
                {
                    Orbital._mthfor(a, Orbital._mthcase(a).getInt());
                    if(Orbital._mthif(a) != i)
                    {
                        Orbital._mthtry(a);
                    }
                }
                catch(Exception exception) { }
            }

           
            {
                a = Orbital.this;
               
            }
        });
        jpanel.add(cIn);
        nDots = new IntegerInput("# dots:", d, 3);
        nDots.addActionListener(new ActionListener() {

            final Orbital a;

            public void actionPerformed(ActionEvent actionevent)
            {
                try
                {
                    Orbital.a(a, Orbital._mthbyte(a).getInt());
                    Orbital._mthtry(a);
                }
                catch(Exception exception) { }
            }

           
            {
                a = Orbital.this;
               
            }
        });
        jpanel.add(nDots);
        add(jpanel, "South");
    }

    private int a(int i, int j, int k, int l)
    {
        return (k * j + (l - k) * i) / l;
    }

    private Color a(Color color, Color color1, int i, int j)
    {
        return new Color(a(color.getRed(), color1.getRed(), i, j), a(color.getGreen(), color1.getGreen(), i, j), a(color.getBlue(), color1.getBlue(), i, j));
    }

    private void a(Graphics g, Dimension dimension)
    {
        double d0 = 0.0D;
        double d1 = 0.0D;
        int i = dimension.width >= dimension.height ? dimension.height : dimension.width;
        double d2 = 0.0D;
        double d3 = 0.0D;
        double d4 = 0.0D;
        double d5 = 0.0D;
        for(int j = 0; j < d; j++)
        {
            for(int k = 0; k < 1000; k++)
            {
                double d7 = a(d0, d1);
                double d9 = _mthif(d0, d1);
                d2 = d7 >= d2 ? d2 : d7;
                d3 = d7 <= d3 ? d3 : d7;
                d4 = d9 >= d4 ? d4 : d9;
                d5 = d9 <= d5 ? d5 : d9;
                d0 = d7;
                d1 = d9;
            }

            Thread.yield();
        }

        double d6 = (double)dimension.width / (d3 - d2);
        double d8 = (double)dimension.height / (d5 - d4);
        d0 = 0.0D;
        d1 = 0.0D;
        for(int l = 0; l < d; l++)
        {
            g.setColor(a(color1, color2, l, d));
            for(int i1 = 0; i1 < 1000; i1++)
            {
                double d10 = a(d0, d1);
                double d11 = _mthif(d0, d1);
                int j1 = (int)(d6 * (d10 - d2));
                int k1 = (int)(d8 * (d11 - d4));
                g.drawLine(j1, k1, j1, k1);
                d0 = d10;
                d1 = d11;
            }

            canvas.repaint();
            Thread.yield();
        }

    }

    public static void main(String args[])
    {
        Orbital orbital = new Orbital();
        orbital.init();
        JFrame jframe = new JFrame();
        jframe.getContentPane().add(orbital);
        jframe.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent windowevent)
            {
                System.exit(0);
            }

        });
        jframe.setTitle("CS330, Fall 2013, Orbital GUI");
        JMenuBar jmenubar = new JMenuBar();
        JMenu jmenu = new JMenu("File");
        jmenubar.add(jmenu);
        JMenuItem jmenuitem = new JMenuItem("Quit");
        jmenuitem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionevent)
            {
                System.exit(0);
            }

        });
        jmenu.add(jmenuitem);
        jframe.setJMenuBar(jmenubar);
        jframe.pack();
        orbital._mthif();
        jframe.setVisible(true);
    }

    private JFrame a()
    {
        Object obj;
        for(obj = this; obj != null && !(obj instanceof JFrame); obj = ((Container) (obj)).getParent()) { }
        return (JFrame)obj;
    }

    private double a(double d, double d1)
    {
        if(d == 0.0D)
        {
            return d1;
        }
        double d2 = Math.log(Math.abs((double)c * d - (double)b));
        double d3 = Math.sin(Math.log(Math.abs((double)b * d - (double)c))) * Math.atan(d2 * d2);
        if(d < 0.0D)
        {
            return d1 + d3;
        } else
        {
            return d1 - d3;
        }
    }

    private double _mthif(double d, double d1)
    {
        return (double)a - d;
    }

    private void _mthif()
    {
        buffer = createImage(canvas.getSize().width, canvas.getSize().height);
        Graphics g = buffer.getGraphics();
        a(g, canvas.getSize());
        canvas.repaint();
    }

    static Image _mthchar(Orbital orbital)
    {
        return orbital.buffer;
    }

    static Color _mthif(Orbital orbital, Color color)
    {
        return orbital.color1 = color;
    }

    static JPanel _mthdo(Orbital orbital)
    {
        return orbital.self;
    }

    static Color _mthgoto(Orbital orbital)
    {
        return orbital.color1;
    }

    static JButton _mthfor(Orbital orbital)
    {
        return orbital.colorChooser1;
    }

    static void _mthtry(Orbital orbital)
    {
        orbital._mthif();
    }

    static Color a(Orbital orbital, Color color)
    {
        return orbital.color2 = color;
    }

    static Color a(Orbital orbital)
    {
        return orbital.color2;
    }

    static JButton _mthelse(Orbital orbital)
    {
        return orbital.colorChooser2;
    }

    static int _mthnew(Orbital orbital)
    {
        return orbital.a;
    }

    static int _mthif(Orbital orbital, int i)
    {
        return orbital.a = i;
    }

    static IntegerInput _mthint(Orbital orbital)
    {
        return orbital.aIn;
    }

    static int _mthvoid(Orbital orbital)
    {
        return orbital.b;
    }

    static int _mthdo(Orbital orbital, int i)
    {
        return orbital.b = i;
    }

    static IntegerInput _mthlong(Orbital orbital)
    {
        return orbital.bIn;
    }

    static int _mthif(Orbital orbital)
    {
        return orbital.c;
    }

    static int _mthfor(Orbital orbital, int i)
    {
        return orbital.c = i;
    }

    static IntegerInput _mthcase(Orbital orbital)
    {
        return orbital.cIn;
    }

    static int a(Orbital orbital, int i)
    {
        return orbital.d = i;
    }

    static IntegerInput _mthbyte(Orbital orbital)
    {
        return orbital.nDots;
    }
}

output:



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote