-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
105 lines (86 loc) · 3.27 KB
/
GUI.java
File metadata and controls
105 lines (86 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
/**
* Generates the GUI used by the user to enter parameters for the Julia Fractal
*/
public class GUI{
private JFrame frame = new JFrame();
JPanel panel = new JPanel();
private boolean color = true;
public GUI(){
juliaGUI();
panel.setLayout(new BoxLayout(panel, 1));
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setTitle("Julia Set Generator");
frame.pack();
frame.setVisible(true);
}
//method for generating GUI elements for a Koch Fractal
@Deprecated
private void kochGUI(){
JSlider kochSlider = new JSlider(0, 4, 4);
kochSlider.setPaintTrack(true);
kochSlider.setPaintTicks(true);
kochSlider.setPaintLabels(true);
kochSlider.setMajorTickSpacing(1);
JButton kochButton = new JButton(new AbstractAction("Create Koch Fractal"){
@Override
public void actionPerformed(ActionEvent arg0) {
new KochFractal(kochSlider.getValue());
}
});
panel.add(kochSlider);
panel.add(kochButton);
}
/**
* Method for generating GUI elements for customizing JuliaFractals
*/
private void juliaGUI() {
//The two fields for entering the real and imaginary parts of the parameter, C
JTextField realField = new JTextField("-0.4", 8);
JTextField imagField = new JTextField("0.6", 8);
//checkbox to determine whether the fractal should be drawn in color
JCheckBox colorBox = new JCheckBox("Enable Color", true);
colorBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == e.SELECTED){
color = true;
} else {
color = false;
}
}
});
//button that generates the JuliaFractal
JButton juliaButton = new JButton(new AbstractAction("Create Julia Fractal"){
@Override
public void actionPerformed(ActionEvent arg0){
//convert Strings from text fields to doubles
double a = Double.parseDouble(realField.getText());
double b = Double.parseDouble(imagField.getText());
ComplexNum c = new ComplexNum(a, b);
new JuliaFractal(c, color);
}
});
//values of C that make cool-looking Julia Sets
String suggestedValues = "\nSuggested Values:\n-0.4+0.6i\n0.285+0.01i\n0.285+0i\n-0.7269+0.1889i\n-0.8-0.15";
//Add all this stuff to the panel.
panel.add(new JLabel("A julia fractal takes a complex parameter, C"));
panel.add(new JLabel("Real Component of C"));
panel.add(realField);
panel.add(new JLabel("Imaginary Component of C"));
panel.add(imagField);
panel.add(juliaButton);
panel.add(colorBox);
panel.add(new JTextArea(suggestedValues));
}
/**
* Main Method of the program.
* Creates a window with the GUI
*/
public static void main(String[] args) {
GUI gui = new GUI();
}
}