/** * Bandscope Receiver Applet 1.0.0 [BAND TYPE AND BAND SELECTOR] * @author Robert J Morton * @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 // Band names for broadcast, amateur, air and marine bands respectively: private static final String bandNames[][] = { {"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)"}, {"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"}, {"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)"}, {"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 private centrefreq cf; // reference to the centre-frequency class private freqspan sp; // reference to the frequency-span class private listeningon lo; // reference to the "listening on" panel class private loader ld; // reference to the loader class instance // selector for type of radio band required private JComboBox BandTypes; // selector for the required radio band private JComboBox Bands; bands(bs cp, centrefreq cf, freqspan sp) { 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 JLabel TypesLab = new JLabel("Select Band Type"); // create band-type selector label cp.add(TypesLab); // add it to applet's content pane TypesLab.setBounds(X,y,W,h); // 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"); BandTypes.addItem("Broadcast"); // set up its permanent 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 the band selector label cp.add(BandLab); // add it to the applet's content pane BandLab.setBounds(X,y,W,h); // set its position and size y += 18; // move down to band selector position Bands = new JComboBox(); // create the band selector Bands.addItem("None"); // absolutely vital to avoid hang-up cp.add(Bands); // add it to the applet's content pane Bands.setBounds(X, y, W, H); // set its position and size Bands.addItemListener( // create a new item listener to listen new bdchl(bdchl.BANDS, this) // for when a new band is selected ); } // set the reference to the "listening on" panel class void setLo(listeningon lo) { this.lo = lo; // because "listening on" is not created until } // after the "bands" object has been created void setLd(loader ld) { // set reference to the loader class instance this.ld = ld; // because the loader is not created until } // after the "bands" object has been created void selBand() { // ACTION TO BE TAKEN WHEN NEW BAND SELECTED sB = Bands.getSelectedIndex(); // index number of selected band sb = sB - 1; // corresponding array index if(sB > 0 && sBT > 0) { // if band is selected sp.setSpan(sbt, sb); // set frequency span for selected band cf.setCF(sbt, sb); // set centre frequency for selected band ld.load(sBT, sB); // trigger loading of appropriate data file } } void selBandType() { // WHEN NEW BANDSCOPE SPAN IS SELECTED sBT = BandTypes.getSelectedIndex(); // index number of selected band type sbt = sBT - 1; // corresponding array index Bands.removeAllItems(); /* remove the band names of the previously-selected band type. */ /* If a valid band is selected (ie not "None"), get the number of bands in this band-type (eg broadcast, amateur). */ if(sBT > 0) { int I = (bandNames[sbt]).length; for(int i = 0; i < I; i++) // For each band of this type, Bands.addItem(bandNames[sbt][i]); // load its name into the band } // choice menu; 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 void setSelectedType(int x) { sBT = x; // set the selected band type variable to the required value BandTypes.setSelectedIndex(x); // Set the band-type selector choice } // menu to the required band-type. // ALLOWS AN EXTERNAL CLASS TO SELECT A BAND OF THE CURRENT TYPE void setSelectedBand(int x) { sB = x; // set the selected band variable to the required value Bands.setSelectedIndex(x); // Set the band selector choice } // menu to the required band. // 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 has been manually selected s = bandNames[sbt][sb]; // get its name else // otherwise s = "default"; // call it the default band return s; } } // LISTENS FOR EVENTS FROM THE CHOICE MENU SELECTORS class bdchl implements ItemListener { // an event from the 'band type selector' choice menu static final int BANDTYPES = 0; static final int 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 class // constructor for a new Choice selection event public bdchl(int id, bands ap) { /* Set the id number pertaining to this instance of 'cl' then set the reference to the instance of the 'bs' applet from which it came. (there will only be one instance anyway). */ this.id = id; this.ap = ap; } // a Choice selection event has occurred public void itemStateChanged(ItemEvent e) { /* Execute the appropriate method in the above class that deals with the selection event concerned. */ switch(id) { case BANDTYPES: ap.selBandType(); break; case BANDS: ap.selBand(); } } }