/** * 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 long R[] = {1000,200,40}; // refresh rate options private static refreshrate sr; // reference to current object private ButtonGroup G; // reference for this JRadioButton group private JRadioButton a, b, // references to individual JRadioButtones within it c; private int I = 3; // number of buttons private movmap mm; // object reference to the main applet private Color bg; // background colour for buttons //construct the radio button panel 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 // to make the buttons lie in a single column setLayout(new GridLayout(I,1)); // incorporate them into a mutually-exclusive group G = new ButtonGroup(); 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 the reference to the instance of the applet } // from which it came. (only ever 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); } } }