/** * Bandscope Receiver Applet 1.0.0 [UPDATE FREQUENCY SELECTOR AND UPDATE BUTTON] * @author Robert J Morton YE572246C * @version 13 March 2002, 22 March 2012 * @copyright Robert J Morton (all rights reserved) */ import javax.swing.*; // swing widgets import java.awt.*; // for graphics operations (GUI) import java.awt.event.*; // for the new-fangled 1.1 event handling class update { private static final int X = 395, // x-coordinate of hold button on applet panel Y = 183, // y-coordinate of hold button on applet panel W = 140, // width of peak hold button H = 30, // height of peak hold button h = 15; // label height private String Age = ""; // age of latest scan data for selected band private JLabel AgeLabel; // label on which the above is displayed private msgpanel mp; // instance reference of the message panel object private loader ld; // instance reference of the loader object update(Container cp, msgpanel mp) { // CONSTRUCTOR this.mp = mp; // instance reference of THE message panel object int y = Y; // y-coordinate of the first Swing widget in this class /* create an "Update Trace" label, add it to the applet's content pane then set its position and size. */ JLabel UpdtLab = new JLabel("Update trace..."); cp.add(UpdtLab); UpdtLab.setBounds(X, y, W, h); y += 18; /* Advance y-coordinate to where the top of the next Swing widget should be placed. */ /* Create the update frequency choice menu, enter its fixed text items, add it to the applet's content pane, set its position and size then create a listener to detect selection events from it. */ JComboBox Update = new JComboBox(); Update.addItem("on demand"); Update.addItem("continuous"); Update.addItem("every minute"); Update.addItem("every 5 mins"); Update.addItem("every 10 mins"); Update.addItem("every 15 mins"); Update.addItem("every 20 mins"); Update.addItem("every 30 mins"); Update.addItem("every hour"); cp.add(Update); Update.setBounds(X,y,W,H); Update.addItemListener(new udchl(udchl.UPDATE,this)); y += 39; /* Advance y-coordinate to where the top of the next Swing widget should be placed. */ /* Create a blank label in which to show the age of the scan data, add it to the applet's content pane then set its position and size. */ AgeLabel = new JLabel(""); cp.add(AgeLabel); AgeLabel.setBounds(X,y,W,h); y += 18; /* Advance y-coordinate to where top of the next Swing widget should be placed. */ /* Create the Update button, add it to the applet's content pane then set its position and size. Create a listener for this button. */ JButton PulBut = new JButton("Update Now"); cp.add(PulBut); PulBut.setBounds(X,y,W,H); PulBut.addActionListener(new updatebl(updatebl.PULBUT,this)); } // set reference to the loader class instance void setLd(loader ld) { this.ld = ld; } // action to be taken when update choice made void selUpdate() { mp.showMsg("new update frequency selected", false); } void pressPulBut() { // action to be taken when Pull button is pressed if(false) { // replace 'false' with server ack signal ld.post(); // send POST command to server to invoke a re-scan } else { mp.showMsg("RX port server currently unavailable.", true); ld.reload(); // trigger a delayed reload of current data } } //!!! THIS MUST BE DONE ON THE EVENT-DESPATCHING THREAD void setAgeLabel(String Age) { AgeLabel.setText(Age); } } // LISTENS FOR EVENTS FROM 'PULL' BUTTON class updatebl implements ActionListener { static final int PULBUT = 0; // 'Pull button pressed' event int id; // one of the above update ap; // the application that called: always the above applet! public updatebl(int id, update ap) { this.id = id; this.ap = ap; } // The 'Pull' button has been clicked public void actionPerformed(ActionEvent e) { switch(id) { case PULBUT: ap.pressPulBut(); break; } } } // LISTENS FOR EVENTS FROM THE CHOICE MENU SELECTORS class udchl implements ItemListener { static final int UPDATE = 0; /* selected item number from the 'up- date frequency selector' choice menu */ int id; //one of the above events update ap; //the application that called: always the above applet! public udchl(int id, update ap) { this.id = id; this.ap = ap; } /* A Choice selection event has occurred from checkbox 'id', so exe- cute the method in the above applet which deals with this choice. */ public void itemStateChanged(ItemEvent e) { switch(id) { case UPDATE: ap.selUpdate(); break; } } }