/** * Refresh Rate Selection Panel for Rob's Moving Map package * @author Robert J Morton * @version 13 November 2007 */ /* This class contains a group of 3 radio buttons for choosing which of the three offered refresh rates is to be used. */ import javax.swing.*; // Java Swing GUI utilities import java.awt.*; // Java Abstract Windowing Toolkit import java.awt.event.*; // for the new-fangled 1.1 event handling public class refreshrate extends JPanel { private static final long serialVersionUID = 13L; // what the hell this is for, I don't know! private static refreshrate sr; // reference to current object /* A reference for this JRadioButton group and to the individual JRadioButtones within it. */ private ButtonGroup G; private JRadioButton a, b, c; private int I = 3; // number of buttons private movmap mm; // object reference to the main applet private Color bg; // background colour for buttons private long R[] = {1000,200,40}; // refresh rate options refreshrate(movmap mm) { this.bg = bg; // background colour for selector buttons this.mm = mm; // local variable for object reference to main applet setOpaque(false); sr = this; //reference to refreshrate object // set layout policy to make the radio buttons lie in a single column setLayout(new GridLayout(I,1)); /* Create a group in which to place the radio buttons so that when one is selected all the others automatically de-select. */ G = new ButtonGroup(); /* Create each of the 3 radio buttons, add it to the Group and to the applet panel, create an item listener for it to listen for when it is clicked by the mouse and then set it visible upon the applet panel. */ a = new JRadioButton("",true); G.add(a); add(a); a.addItemListener(new ratebut(0,this)); a.setOpaque(false); b = new JRadioButton("",false); G.add(b); add(b); b.addItemListener(new ratebut(1,this)); b.setOpaque(false); c = new JRadioButton("",false); G.add(c); add(c); c.addItemListener(new ratebut(2,this)); c.setOpaque(false); } void selectRate(int i) { // REFRESH RATE i HAS JUST BEEN SELECTED mm.setRefreshRate(R[i]); // set refresh rate in main applet } } // LISTENS FOR EVENTS FROM REFRESH RATE SELECTION BUTTONS class ratebut implements ItemListener { int id; // one of the above events refreshrate sr; // the application that called: always the above applet! // constructor for a new JRadioButton event public ratebut(int id, refreshrate sr) { this.id = id; // set id number of this instance of 'refreshrate' this.sr = sr; // set reference to this instance of the applet } // from which it came. (there'll only be one instance). // a JRadioButton event has occurred from JRadioButton 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: sr.selectRate(0); break; case 1: sr.selectRate(1); break; case 2: sr.selectRate(2); } } }