/** * Refresh Rate Selection Panel for Rob's Moving Map package * @author Robert J Morton YE572246C * @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 { // what the hell this is for, I don't know! private static final long serialVersionUID = 2012L; private static refreshrate sr; // reference to current object private ButtonGroup G; // reference for this JRadioButton group private JRadioButton a, b, c; // references to the JRadioButtones in it 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) { // construct the radio button panel this.bg = bg; // background colour for selector buttons this.mm = mm; // local variable for object reference to main applet sr = this; // reference to refreshrate object setOpaque(false); // make the panel transparent // This is to make the buttons lie in a single column setLayout(new GridLayout(I,1)); G = new ButtonGroup(); // Create a radio button GROUP for the buttons // Create each of the buttons, add it to the GROUP and also to the panel a = new JRadioButton("", true); G.add(a); add(a); b = new JRadioButton("", false); G.add(b); add(b); c = new JRadioButton("", false); G.add(c); add(c); // Create a listener for each button and make it transparent. a.addItemListener(new ratebut(0, this)); a.setOpaque(false); b.addItemListener(new ratebut(1, this)); b.setOpaque(false); c.addItemListener(new ratebut(2, this)); c.setOpaque(false); } // Refresh rate 'i' has just been selected so set it in the main applet void selectRate(int i) { mm.setRefreshRate(R[i]); } } // 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 pertaining to this instance of 'refreshrate' this.sr = sr; // set the reference to the instance of the applet } //from which it came. (there will 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); } } }