import java.awt.*; public class MandelControl extends Frame { double xMin, xMax, yMin, yMax; int iter; int pixel; TextField xMinField = new TextField(9); TextField xMaxField = new TextField(9); TextField yMinField = new TextField(9); TextField yMaxField = new TextField(9); TextField iterField = new TextField(5); TextField pixelField = new TextField(5); Button Okay = new Button("Okay"); Button Cancel = new Button("Cancel"); Button Apply = new Button("Apply"); Mandel master; public MandelControl(Mandel _master, double _xMin, double _xMax, double _yMin, double _yMax, int _iter, int _pixel) { super("Mandelbrot Controls"); master = _master; setParams(_xMin,_xMax,_yMin,_yMax,_iter,_pixel); Panel ButtonRow = new Panel(); ButtonRow.setLayout(new FlowLayout()); ButtonRow.add(Okay); ButtonRow.add(Apply); ButtonRow.add(Cancel); Panel Row1 = new Panel(); Row1.setLayout(new FlowLayout()); Row1.add(new Label("xMin:")); Row1.add(xMinField); Row1.add(new Label("xMax:")); Row1.add(xMaxField); Panel Row2 = new Panel(); Row2.setLayout(new FlowLayout()); Row2.add(new Label("yMin:")); Row2.add(yMinField); Row2.add(new Label("yMax:")); Row2.add(yMaxField); Panel Row3 = new Panel(); Row3.setLayout(new FlowLayout()); Row3.add(new Label("# of iterations:")); Row3.add(iterField); Panel Row4 = new Panel(); Row4.setLayout(new FlowLayout()); Row4.add(new Label("Size of pixels:")); Row4.add(pixelField); setLayout(new GridLayout(5,1,5,5)); add(Row1); add(Row2); add(Row3); add(Row4); add(ButtonRow); validate(); pack(); resize(preferredSize()); } /* =========================================================== */ public void setParams(double _xMin, double _xMax, double _yMin, double _yMax, int _iter, int _pixel) { xMin = _xMin; xMax = _xMax; yMin = _yMin; yMax = _yMax; iter = _iter; pixel = _pixel; xMinField.setText (String.valueOf(_xMin)); xMaxField.setText (String.valueOf(_xMax)); yMinField.setText (String.valueOf(_yMin)); yMaxField.setText (String.valueOf(_yMax)); iterField.setText (String.valueOf(_iter)); pixelField.setText(String.valueOf(_pixel)); } /* =========================================================== */ private void handleOkay() { try { xMin = Double.valueOf(xMinField.getText().trim()).doubleValue(); xMax = Double.valueOf(xMaxField.getText().trim()).doubleValue(); yMin = Double.valueOf(yMinField.getText().trim()).doubleValue(); yMax = Double.valueOf(yMaxField.getText().trim()).doubleValue(); iter = Integer.parseInt(iterField.getText().trim()); pixel = Integer.parseInt(pixelField.getText().trim()); master.setDrawingParams(xMin,xMax,yMin,yMax,iter,pixel); } catch(NumberFormatException e) { setParams(xMin, xMax, yMin, yMax, iter, pixel); } } /* =========================================================== */ public boolean handleEvent(Event e) { if (e.id == Event.WINDOW_DESTROY) { hide(); return true; } else return super.handleEvent(e); } /* =========================================================== */ public boolean action(Event e, Object arg) { if (e.target == Okay) { handleOkay(); hide(); return true; } else if (e.target == Apply) { handleOkay(); return true; } if (e.target == Cancel) { hide(); return true; } else return false; } }