// StarFieldPanel.java // Author: P Gray // instrumented starfield for displaying financial data import java.awt.*; import java.awt.event.*; import java.util.Vector; import java.util.Enumeration; class StarFieldPanel extends Panel implements ActionListener { private TradeViewer application; private StarFieldView starFieldView; private TextField scaleField; public StarFieldPanel(TradeViewer application) { // initialise this.application = application; setLayout(new BorderLayout()); // creat and add components // first set an initial scale double scale = 5.0; // create and add a textfield to edit the scale scaleField = new TextField(new Double(scale).toString(),10); add("North", scaleField); // create the starfield // and load it with data starFieldView = new StarFieldView(application.sourceDomain(),scale); // add starfield to me add("Center",starFieldView); // add a listener on the scale editor text widget scaleField.addActionListener(this); } public void actionPerformed(ActionEvent ae) { // handles events from the scale widget listener // this is an example of a parent listening to a child's events double scaleVal; scaleVal = new Double(ae.getActionCommand()).doubleValue(); starFieldView.setScale(scaleVal); } // starfield operations public StarFieldView starFieldView() { return starFieldView; } public void update(int row) { // updates a single point in the starfield based on ith element of the // source domain // pass it on to the starFieldView starFieldView.update(row); } } // end StarFieldPanel