/** * Bandscope Receiver Applet 1.0.0 [CENTRE-FREQUENCY ENTRY FIELD] * @author Robert J Morton YE572246C * @version 13 March 2002, 20 March 2012 * @copyright Robert J Morton (all rights reserved) */ import java.awt.*; // for graphics operations (GUI) import javax.swing.*; // swing widgets import java.awt.event.*; // for the new-fangled 1.1 event handling class updown { private static final int CX = 230, // x-coordinate of graph centre CY = 132, // y-coordinate of graph centre D = 110, // horizontal distance of the buttons from scope centre W = 25, // width of a button H = 50; // height of a button private int Y = CY - H/2; // y-coordinate of the tops of the buttons private listeningon lo; private JButton DnBut, // set up the Down button UpBut; // set up the Up button updown(Container cp) { Font font = new Font("Serif",Font.BOLD,16); // font for applet canvas DnBut = new JButton(); // set up the Down button cp.add(DnBut); DnBut.setBounds(CX - D - W,Y,W,H); DnBut.setMargin(new Insets(3,3,3,3)); DnBut.setFont(font); DnBut.setText("-"); DnBut.addActionListener(new updownbl(updownbl.DNBUT,this)); UpBut = new JButton(); // set up the Up button cp.add(UpBut); UpBut.setBounds(CX + D,Y,W,H); UpBut.setMargin(new Insets(3,3,3,3)); UpBut.setFont(font); UpBut.setText("+"); UpBut.addActionListener(new updownbl(updownbl.UPBUT,this)); } void setLo(listeningon lo) {this.lo = lo;} //action to be taken when Up button is pressed void pressUpBut() {lo.inchFreq( 1);} //action to be taken when Down button is pressed void pressDnBut() {lo.inchFreq(-1);} } class updownbl implements ActionListener { static final int UPBUT = 0; // 'Up button pressed' event static final int DNBUT = 1; // 'Down button pressed' event int id; // one of the above updown ap; // the application that called: always the above applet! // constructor for a new command public updownbl(int id, updown ap) { this.id = id; this.ap = ap; } // one of the buttons has been clicked public void actionPerformed(ActionEvent e) { switch(id) { // id of this instance of ActionEvent case UPBUT: ap.pressUpBut(); break; // it was the 'Up' button case DNBUT: ap.pressDnBut(); break; // it was the 'Down' button } } }