1: import java.awt.*; 2: 3: public abstract class MultiPlotter extends Plotter { 4: 5: abstract public void initMultiPlotter(); 6: 7: public void init() { 8: super.init(); 9: initMultiPlotter(); 10: } 11: 12: final public void addFunction(Function f, Color c) { 13: if (numOfFunctions < MAX_FUNCTIONS && f != null) { 14: functions[numOfFunctions] = f; 15: colors[numOfFunctions++] = c; 16: } 17: } 18: 19: protected void plotFunction(Graphics g) { 20: for (int i = 0; i < numOfFunctions; i++) { 21: if (functions[i] != null) { 22: Color c = colors[i]; 23: if (c != null) 24: g.setColor(c); 25: else 26: g.setColor(Color.black); 27: for (int px = 0; px < d.width; px++) { 28: try { 29: double x = (double) (px - xorigin) / (double) xratio; 30: double y = functions[i].apply(x); 31: int py = yorigin - (int) (y * yratio); 32: g.fillOval(px - 1, py - 1, 3, 3); 33: } catch (Exception e) {} 34: } 35: } 36: } 37: } 38: 39: 40: public double func(double x) { 41: return 0.0; 42: } 43: 44: protected static int MAX_FUNCTIONS = 5; 45: protected int numOfFunctions = 0; 46: protected Function functions[] = new Function[MAX_FUNCTIONS]; 47: protected Color colors[] = new Color[MAX_FUNCTIONS]; 48: }