import java.awt.*; public class TextSlide extends Panel { TextField textField; Scrollbar slider; GroupVelocity owner; double theVal; int scrollmin = 0, scrollmax = 1000; double minVal = 0.0, maxVal = 5.0; TextSlide(GroupVelocity controller, String myLabel, double min, double max) { owner = controller; minVal = min; maxVal = max; GridBagConstraints gbc = new GridBagConstraints(); GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 0; gbc.gridy = 0; Label title = new Label(myLabel); add(title); gbl.setConstraints(title,gbc); gbc.anchor = GridBagConstraints.EAST; gbc.gridx = 1; textField = new TextField("0.6",10); add(textField); gbl.setConstraints(textField,gbc); gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 2; slider = new Scrollbar(Scrollbar.HORIZONTAL,1,100,scrollmin,scrollmax); add(slider); gbl.setConstraints(slider,gbc); setValue(0.6); validate(); } public boolean action(Event e, Object arg) { if (e.target == textField) { double f = getTextValue(); if (f>=minVal) { theVal = f; setSliderValue(f); owner.changeParam(this); } } return true; } // This sort of event is more general. We use it to alert us to the moving slider, // but the class takes care of actually moving the control. // Stop and start animating on mouse clicks. public boolean handleEvent(Event e) { if (e.target == slider) { double sv = getSliderValue(); theVal = sv; setTextValue(sv); owner.changeParam(this); } return super.handleEvent(e); } // Set the slider and text fields to the same floating point number. public void setValue(double f) { if (fmaxVal) { f = maxVal; } theVal = f; setTextValue(f); setSliderValue(f); } public double getValue() { return theVal; } // Calculate what slider position corresponds to a number and set the position. private void setSliderValue(double f) { slider.setValue((int)(scrollmin+ (f-minVal)/(maxVal-minVal)*(scrollmax-scrollmin))); } // A local function to find the number typed in the textbox. private double getTextValue() { double f; // Catch possible non-numbers. try { f = Double.valueOf(textField.getText()).doubleValue(); } catch (java.lang.NumberFormatException e) { f = minVal-1.0; } // Don't let them kill the animation with crazy numbers. if (f>maxVal) { f = maxVal; setTextValue(f); } else if (f