Example Tool for the MVTThis document goes through a single Tool (the PlotTool) in detail. The full source code is located here. The package declarationEach tool (or related groups of tools) are located in a package: package tools.plottool; The class declarationIf the tool is to only have a single plotting panel, it should extend GraphicsTool. public class PlotTool extends GraphicsTool The member variablesThis section obviously varies from tool to tool. Here are some of the reasons for the member variables in this case:
// Stores information about the function, its derivative and // its independent variable. private Function function = null; private Function derivative = null; private Variable indVar = null; // This is where the plotting of the functions is done. private Line line = null; // The input and option panels is where the user can // add function input and set options such as color. private PlotInput inputPanel = new PlotInput(); private PlotOptions optionsPanel = new PlotOptions(); The ConstructorThe constructor has a number of key features:
public PlotTool() { super("Function Plotter"); super.setInputPanel(inputPanel); super.setOptionsPanel(optionsPanel); setHelpFile("FunctionPlotter/plot1d.html","Function Plotter Help"); // Add the Variable update Listener inputPanel.indVariableBox.getTextBox(). addCaretListener(new CaretListener(){ public void caretUpdate(CaretEvent e){ inputPanel.functionBox .setLabel("f("+inputPanel.indVariableBox); } }); // Add a listener to the plot button inputPanel.plotButton.addActionListener(new PlotButtonListener()); inputPanel.clearButton.addActionListener(new ClearButtonListener()); } Other methodThe following methods are also in the PlotTool:
|