/** * Bandscope Receiver Applet 1.0.0 [BAND TYPE AND BAND SELECTOR] * @author Robert J Morton YE572246C * @version 13 March 2002, 20 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 bands { private static final int X = 395, // x-coordinate of these components on applet panel Y = 69, // y-coordinate of band type label on applet panel W = 140, // width of combobox H = 30, // height of combobox h = 15; // label area height private static final String bandNames[][] = { // Broadcast Bands {"None", "Long Wave", "Medium Wave", "120 metre", "90 metre", "75 metre", "60 metre", "49 metre", "39 metre", "31 metre", "25 metre", "22 metre", "19 metre", "16 metre", "13 metre", "11 metre", "FM (Low half)", "FM (High half)"}, // Amateur Bands {"None", "Top Band", "80 metre", "40 metre", "30 metre", "20 metre", "17 metre", "15 metre", "12 metre", "10 metre", "6 metre", "4 metre", "2 metre", "70 cm", "23 cm"}, // Air Bands {"None", "LF Navigation", "3 Meg", "3½ Meg", "4½ Meg", "5½ Meg", "6½ Meg", "9 Meg", "10 Meg", "11 Meg", "13 Meg", "15 Meg", "18 Meg", "22 Meg", "23 Meg", "VHF Civil (Lower Half)", "VHF Civil (Upper Half)"}, // Marine Bands {"None", "2-3 Meg", "6½ Meg", "8½ Meg", "12-13 Meg", "18.8 Meg", "19.7 Meg", "22-23 Meg", "25 Meg", "Marine VHF"} }; private int sBT = 0, // index number of selected band type sbt = 0, // array index number of selected band type sB = 0, // index number of selected band sb = 0; // array index number of selected band // Reference to the: private centrefreq cf; // centre-frequency class private freqspan sp; // frequency-span class private listeningon lo; // "listening on" panel class private loader ld; // loader class instance private JComboBox BandTypes, // Choice selector for the type of radio band required Bands; // Choice selector for the required radio band bands(Container cp, centrefreq cf, freqspan sp) { // CONSTRUCTOR this.cf = cf; // set ref to centre-frequency class to local variable this.sp = sp; // set ref to centre-frequency class to local variable int y = Y; // y-coordinate of the band-type selector's label // Create the band-type selector label JLabel TypesLab = new JLabel("Select Band Type"); cp.add(TypesLab); // add it to the applet's content pane TypesLab.setBounds(X,y,W,h); // then set its position and size y += 18; // move down to the band-type selector position BandTypes = new JComboBox(); // Create the band-type selector. BandTypes.addItem("None"); // Set up its permanent BandTypes.addItem("Broadcast"); // menu entries. BandTypes.addItem("Amateur"); BandTypes.addItem("Aircraft"); BandTypes.addItem("Marine"); cp.add(BandTypes); // Add it to the applet's content pane. BandTypes.setBounds(X,y,W,H); // set its position and size /* Create a new item listener to listen for when a new band-type is selected. */ BandTypes.addItemListener(new bdchl(bdchl.BANDTYPES,this)); y += 39; // move down to the band selector label position JLabel BandLab = new JLabel("Select Band"); // Create band selector label cp.add(BandLab); // add it to the applet's content pane BandLab.setBounds(X,y,W,h); // and set its position and size y += 18; // move down to the band selector position Bands = new JComboBox(); // Create the band selector menu, Bands.addItem("None"); // add at least one item [this is abso- // lutely vital to avoid a hang-up] cp.add(Bands); // add it to the applet's content pane Bands.setBounds(X,y,W,H); // set its position and size // Create a new item listener to listen for when a new band is selected. Bands.addItemListener(new bdchl(bdchl.BANDS, this)); } /* Set reference to the "listening on" panel class because "listening on" is not created until after the "bands" object has been created. */ void setLo(listeningon lo) { this.lo = lo; } /* Set reference to the loader class instance because the loader is not created until after the "bands" object has been created. */ void setLd(loader ld) { this.ld = ld; } void selBand() { // ACTION TO BE TAKEN WHEN NEW BAND IS SELECTED sB = Bands.getSelectedIndex(); // index number of selected band sb = sB - 1; // its corresponding array index if(sB > 0 && sBT > 0) { // If band is selected sp.setSpan(sbt, sb); // set its appropriate frequency span cf.setCF(sbt, sb); // set its centre frequency ld.load(sBT, sB); // trigger loading of the appropriate data file } } void selBandType() { // DO WHEN NEW BANDSCOPE SPAN IS SELECTED // Set index number & corresponding array index of selected band type. sBT = BandTypes.getSelectedIndex(); sbt = sBT - 1; // Remove the band names of the Bands.removeAllItems(); // previously-selected band type. if(sBT > 0) { // If valid band selected (not None) int I = (bandNames[sbt]).length; // get number of bands of this type for(int i = 0; i < I; i++) // For each band of this type: // Load the appropriate bands into the band choice menu. Bands.addItem(bandNames[sbt][i]); } else // else if "None" is selected, bands.addItem("None"); // set up a null band lo.setReceiving(false); // stop receiving } /* ALLOWS AN EXTERNAL CLASS TO SELECT A BAND-TYPE: set the selected band type variable to the required value and the band-type selector choice menu to the required band-type. */ void setSelectedType(int x) { sBT = x; BandTypes.setSelectedIndex(x); } /* ALLOWS AN EXTERNAL CLASS TO SELECT A BAND OF THE CURRENT TYPE: set the selected band variable to the required value and the band selector choice menu to the required band. */ void setSelectedBand(int x) { sB = x; Bands.setSelectedIndex(x); } // ALLOWS "SCOPE" CLASS TO GET THE CURRENTLY SELECTED BAND TYPE int getSelectedType() {return sBT;} // ALLOWS "SCOPE CLASS TO GET THE CURRENTLY SELECTED BAND int getSelectedBand() {return sB;} String getBandName() { // USED BY "LOADER" String s; if(sBT > 0 && sB > 0) // If a specific band's been manually selected s = bandNames[sbt][sb]; // then get its name else s = "default"; // otherwise call it the default band. return s; } } // LISTENS FOR EVENTS FROM THE CHOICE MENU SELECTORS class bdchl implements ItemListener { static final int BANDTYPES = 0, // an event from the 'band type selector' choice menu BANDS = 1; // an event from the 'band selector' choice menu int id; // one of the above events bands ap; // the application that called: always the above applet! // constructor for a new Choice selection event public bdchl(int id, bands ap) { this.id = id; // set the id number pertaining to this instance of 'cl' this.ap = ap; // set the reference to the instance of the 'bs' applet } // from which it came. (there can only be one instance). // a Choice selection event has occurred public void itemStateChanged(ItemEvent e) { switch(id) { /* Execute the appropriate method in the above class that deals with the selection event concerned. */ case BANDTYPES: ap.selBandType(); break; case BANDS: ap.selBand(); break; } } }